Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Database testing


Published on

SQL Data base , SQL Interview questions ,

Published in: Education, Technology
  • Be the first to comment

Database testing

  1. 1. Q.What is Database testing ? Testing the backend databases like comparing the actual results with expected results. Q. What we test in database testing Data bas testing basically include the following. 1)Data validity testing. 2)Data Integrity testing 3)Performance related to database. 4)Testing of Procedure, triggers and functions. For doing data validity testing you should be good in SQL queries For data integrity testing you should know about referential integrity and different constraint. For performance related things you should have idea about the table structure and design. For testing Procedure triggers and functions you should be able to understand the same. Q.What are the different stages involved in Database Testing? In DB testing we need to check for, 1.The field size validation 2.Check constraints. 3.Indexes are done or not (for performance related issues) 4.Stored procedures. 5.The field size defined in the application is matching with that in the db. Q.What SQL statements have you used in Database Testing? DDL DDL is Data Definition Language statements. Some examples: • CREATE • ALTER - • DROP -• TRUNCATE -• COMMENT - • RENAME – DML DML is Data Manipulation Language statements. Some examples: • SELECT - • INSERT - • UPDATE - • DELETE - • MERGE - UPSERT -• CALL - • EXPLAIN PLAN - • LOCK TABLE – DCL DCL is Data Control Language statements. Some examples: • GRANT - • REVOKE - • COMMIT - • SAVEPOINT - • ROLLBACK - COMMIT -• SET TRANSACTION - This are the Database testing commands. Q.What is a Primary Key? A primary key is a single column or multiple columns defined to have unique values that can be used as row identifications Q.What is a Foreign Key? A foreign key is a single column or a multiple columns defined to have values that can be mapped to a primary key in another table. Q.What we normally check for in the Database Testing? Database testing involves some in-depth knowledge of the given application and requires more defined plan of approach to test the data. Key issues include: 1)data Integrity 2)data validity 3)data manipulation and updates. Tester must be aware of the database design concepts and implementation rules Q.How to Test database in Manually? Explain with an example Observing that operations, which are operated on front-end is effected on back-end or not. The approach is as follows: While adding a record thru' front-end check back-end that addition of record is effected or not. So same for delete, update... Ex: Enter employee record in database thru' front-end and check if the record is added or not to the back-end (manually). Q.What is an Index? An index is a single column or multiple columns defined to have values pre-sorted to speed up data retrieval speed.
  2. 2. Q.What are NULL values? NULL represents no value NULL is not the same as an empty string ‘’ NULL is not same as zero value (0) NULL can be used as any data type NULL should not be used in any comparison operators NULL has its own equality operator IS and not-equality operator IS NOT Q.What is the difference between oracle, sql and sql server ? •Oracle is based on RDBMS. •SQL is Structured Query Language. •SQL Server is another tool for RDBMS provided by MicroSoft. Q.Why you need indexing? where that is Stored and what you mean by schema object? For what purpose we are using view? We can't create an Index on Index.. Index is stoed in user_index table. Every object that has been created on Schema is Schema Object like Table, View etc. If we want to share the particular data to various users we have to use the virtual table for the Base table. So that is a view. Indexing is used for faster search or to retrieve data faster from various table. Schema containing set of tables, basically schema means logical separation of the database. View is crated for faster retrieval of data. It's customized virtual table. we can create a single view of multiple tables. Only the drawback is..view needs to be get refreshed for retrieving updated data. Q.What is the difference between TRUNCATE and DELETE commands? •Both will result in deleting all the rows in the table .TRUNCATE call cannot be rolled back as it is a DDL command and all memory space for that table is released back to the server. TRUNCATE is much faster.Whereas DELETE call is an DML command and can be rolled back. Q.Which system table contains information on constraints on all the tables created ? USER_CONSTRAINTS, system table contains information on constraints on all the tables created Q.what operator performs pattern matching? Pattern matching operator is LIKE and it has to used with two attributes 1.% means matches zero or more characters and 2._( underscore ) means matching exactly one character Q.What is cluster.cluster index and non cluster index ? Clustered Index:- A Clustered index is a special type of index that reorders the way records in the table are physically stored. Therefore table may have only one clustered index.Non-Clustered Index:- A Non-Clustered index is a special type of index in which the logical order of the index does not match the physical stored order of the rows in the disk. The leaf nodes of a non-clustered index does not consists of the data pages. instead the leaf node contains index rows. Q.What is GROUP BY? The GROUP BY keywords has been added to SQL because aggregate functions (like SUM) return the aggregate of all column values every time they are called. Without the GROUP BY functionality, finding the sum for each individual group of column values was not possible. Q.What are defaults? Is there a column to which a default can't be bound? A default is a value that will be used by a column, if no value is supplied to that column while inserting data. IDENTITY columns and timestamp columns can't have defaults bound to them. Q.What is an extended stored procedure? Can you instantiate a COM object by using T-SQL? An extended stored procedure is a function within a DLL (written in a programming language like C, C++ using Open Data Services (ODS) API) that can be called from T-SQL, just the way we call normal stored procedures using the EXEC statement. See books online to learn how to create extended stored procedures and how to add them to SQL Server. You can instantiate a COM (written in languages like VB, VC++) object from T-SQL by using sp_OACreate stored procedure.
  3. 3. Q.What is Trigger? A trigger is a SQL procedure that initiates an action when an event (INSERT, DELETE or UPDATE) occurs. Triggers are stored in and managed by the DBMS. Triggers are used to maintain the referential integrity of data by changing the data in a systematic fashion. A trigger cannot be called or executed; DBMS automatically fires the trigger as a result of a data modification to the associated table. Triggers can be viewed as similar to stored procedures in that both consist of procedural logic that is stored at the database level. Stored procedures, however, are not event-drive and are not attached to a specific table as triggers are. Stored procedures are explicitly executed by invoking a CALL to the procedure while triggers are implicitly executed. In addition, triggers can also execute stored procedures. Q.What is User Defined Functions? What kind of User-Defined Functions can be created? User-Defined Functions allow defining its own T-SQL functions that can accept 0 or more parameters and return a single scalar data value or a table data type. Different Kinds of User-Defined Functions created are: 1.Scalar User-Defined Function A Scalar user-defined function returns one of the scalar data types. Text, ntext, image and timestamp data types are not supported. These are the type of user-defined functions that most developers are used to in other programming languages. You pass in 0 to many parameters and you get a return value. 2.Inline Table-Value User-Defined Function An Inline Table-Value user-defined function returns a table data type and is an exceptional alternative to a view as the user-defined function can pass parameters into a T-SQL select command and in essence provide us with a parameterized, non-updateable view of the underlying tables. 3.Multi-statement Table-Value User-Defined Function A Multi-Statement Table-Value user-defined function returns a table and is also an exceptional alternative to a view as the function can support multiple T-SQL statements to build the final result where the view is limited to a single SELECT statement. Also, the ability to pass parameters into a TSQL select command or a group of them gives us the capability to in essence create a parameterized, non-updateable view of the data in the underlying tables. Within the create function command you must define the table structure that is being returned. After creating this type of user-defined function, It can be used in the FROM clause of a T-SQL command unlike the behavior found when using a stored procedure which can also return record sets Q.What is Identity? Identity (or AutoNumber) is a column that automatically generates numeric values. A start and increment value can be set, but most DBA leave these at 1. A GUID column also generates numbers; the value of this cannot be controlled. Identity/GUID columns do not need to be indexed. Q.What is blocking and how would you troubleshoot it? Blocking happens when one connection from an application holds a lock and a second connection requires a conflicting lock type. This forces the second connection to wait, blocked on the first. Q.Determine the name sex and age of the oldest student. SELECT Name, Gender, (CURRENT_DATE-Dtnaiss)/365 AS Age FROM Student WHERE (CURRENT_DATE-Dtnaiss) /365 = ( SELECT MAX(( CURRENT_DATE-Dtnaiss) /365) FROM Student); Q.Common SQL Syntax used in database interaction a.Select Statement SELECT "column_name" FROM "table_name" b.Distinct SELECT DISTINCT "column_name" FROM "table_name" c.Where SELECT "column_name" FROM "table_name" WHERE "condition" d.And/Or SELECT "column_name" FROM "table_name" WHERE "simple condition" {[AND|OR] "simple condition"}+ e.In SELECT "column_name" FROM "table_name" WHERE "column_name" IN ('value1', 'value2', ...) f.Between SELECT "column_name" FROM "table_name" WHERE "column_name" BETWEEN 'value1' AND 'value2'
  4. 4. g.Like SELECT "column_name" FROM "table_name" WHERE "column_name" LIKE {PATTERN} h.Order By SELECT "column_name" FROM "table_name" [WHERE "condition"] ORDER BY "column_name" [ASC, DESC] i.Count SELECT COUNT("column_name") FROM "table_name" j.Group By SELECT "column_name1", SUM("column_name2") FROM "table_name" GROUP BY "column_name1" k.Having SELECT "column_name1", SUM("column_name2") FROM "table_name" GROUP BY "column_name1" HAVING (arithematic function condition) l.Create Table Statement CREATE TABLE "table_name" ("column 1" "data_type_for_column_1","column 2" "data_type_for_column_2",…) m.Drop Table Statement DROP TABLE "table_name" n.Truncate Table Statement TRUNCATE TABLE "table_name" m.Insert Into Statement INSERT INTO "table_name" ("column1", "column2", ...) VALUES ("value1", "value2", ...) o.Update Statement UPDATE "table_name" SET "column_1" = [new value] WHERE {condition} p.Delete From Statement DELETE FROM "table_name" WHERE {condition} Q.SQL CREATE VIEW Syntax CREATE VIEW view_name AS SELECT column_name(s) FROM table_name WHERE condition Q.How to find out the 10th highest salary in SQL query? Table - Tbl_Test_Salary Column - int_salary select max(int_salary) from Tbl_Test_Salary where int_salary in(select top 10 int_Salary from Tbl_Test_Salary order by int_salary) Q.How to test a SQL Query in WinRunner? With out using Database Checkpoints? By writing scripting procedure in the TCL we can connect to the database and we can test database and queries. Q.How does you test whether a database in updated when information is entered in the front end? With database check point only in WinRunner, but in manual we will go to front end using some information. Will get some session names using that session names we search in backend. If that information is correct then we will see query results. Q.Write a query to find the 5th details from a table SELECT column_name FROM table_name WHERE auto_incremented_id= (SELECT TOP 1 auto_incremented_id FROM (SELECT TOP 3 auto_incremented_id FROM employee ORDER BY auto_incremented_id ASC) table_name ORDER BY auto_incremented_id DESC); Q.Write a Query to display the Top N rows ? MySQL SELECT column_name FROM table_name LIMIT number
  5. 5. SQL Server SELECT TOP number/percent column_name FROM table_name Oracle SELECT column_name FROM table_name WHERE ROWNUM<= number Q.Difference between Stored Procedure and Trigger? •we can call stored procedure explicitly. •but trigger is automatically invoked when the action defined in trigger is done. ex: create trigger after Insert on •this trigger invoked after we insert something on that table. •Stored procedure can't be inactive but trigger can be Inactive. •Triggers are used to initiate a particular activity after fulfilling certain condition.It need to define and can be enable and disable according to need. Q.What is the advantage to use trigger in your PL? A trigger is a database object directly associated with a particular table. It fires whenever a specific statement/type of statement is issued against that table. The types of statements are insert,update,delete and query statements. Basically, trigger is a set of SQL statements A trigger is a solution to the restrictions of a constraint. For instance: 1.A database column cannot carry PSEUDO columns as criteria where a trigger can. 2. A database constraint cannot refer old and new values for a row where a trigger can. Triggers are fired implicitly on the tables/views on which they are created. There are various advantages of using a trigger. Some of them are: •Suppose we need to validate a DML statement(insert/Update/Delete) that modifies a table then we can write a trigger on the table that gets fired implicitly whenever DML statement is executed on that table. •Another reason of using triggers can be for automatic updation of one or more tables whenever a DML/DDL statement is executed for the table on which the trigger is created. •Triggers can be used to enforce constraints. For eg : Any insert/update/ Delete statements should not be allowed on a particular table after office hours. For enforcing this constraint Triggers should be used. •Triggers can be used to publish information about database events to subscribers. Database event can be a system event like Database startup or shutdown or it can be a user even like User loggin in or user logoff. Q.What are the tradeoffs with having indexes? 1.Faster selects, slower updates. 2.Extra storage space to store indexes. Updates are slower because in addition to updating the table you have to update the index. Q.What is "normalization"? "Denormalization"? Why do you sometimes want to denormalize? Normalizing data means eliminating redundant information from a table and organizing the data so that future changes to the table are easier. Denormalization means allowing redundancy in a table. The main benefit of denormalization is improved performance with simplified data retrieval and manipulation. This is done by reduction in the number of joins needed for data processing. Q.What is a "constraint"? A constraint allows you to apply simple referential integrity checks to a table. There are four primary types of constraints PRIMARY/UNIQUE - enforces uniqueness of a particular table column. But by default primary key creates a clustered index on the column, where are unique creates a non-clustered index by default. Another major difference is that, primary key doesn't allow NULLs, but unique key allows one NULL only DEFAULT - specifies a default value for a column in case an insert operation does not provide one. FOREIGN KEY - validates that every value in a column exists in a column of another table. CHECK - checks that every value stored in a column is in some specified list. Each type of constraint performs a specific type of action. Default is not a constraint. NOT NULL is one more constraint which does not allow values in the specific column to be null. And also it the only constraint which is not a table level constraint. Q.What is the system function to get the current user's details such as userid etc. ? USER USER_ID USER_NAME CURRENT_USER
  6. 6. SUSER_SID HOST_NAME SYSTEM_USER SESSION_USER Q.What is Stored Procedure? A stored procedure is a named group of SQL statements that have been previously created and stored in the server database. Stored procedures accept input parameters so that a single procedure can be used over the network by several clients using different input data. And when the procedure is modified, all clients automatically get the new version. Stored procedures reduce network traffic and improve performance. Stored procedures can be used to help ensure the integrity of the database. Q.What are the different isolation levels ? An isolation level determines the degree of isolation of data between concurrent transactions. The default SQL Server isolation level is Read Committed. Here are the other isolation levels (in the ascending order of isolation): Read Uncommitted, Read Committed, Repeatable Read, Serializable. Q.What would happen if you create an index on each column of a table ? If you create an index on each column of a table, it improves the query performance, as the query optimizer tool of the Database engine can choose from all the existing indexes to come up with an efficient execution plan. At the same time, data modification operations (such as INSERT, UPDATE, DELETE) will become slow, as every time data changes in the table, all the indexes need to be updated. Another disadvantage is that, indexes need disk space, the more indexes you have, more disk space is used. Q.The SQL statement to find the departments that have employees with a salary higher than the average employee salary SELECT name FROM dept WHERE id IN ( SELECT dept_id FROM emp WHERE sal> (SELECT avg(sal)FROM emp) ) Q.Write the SQL to use a sub query which will not return any rows - when just the table structure is required and not any of the data. CREATE TABLE new_table AS SELECT * from table_orig WHERE 1=0; The sub query returns no data but does return the column names and data types to the 'create table' statement.