You are on page 1of 22

Software testing - Questions and Answers - SQL Interview Questions

1. Q. What does SQL stand for? A. Structured Query Language 2. Q. How do you select all records from the table? A. Select * from table_name; 3. Q. What is a join? A. Join is a process of retrieve pieces of data from different sets (tables) and returns them to the user or program as one “joined” collection of data. 4. Q. What kinds of joins do you know? Give examples. A. We have self join, outer joint (LEFT, RIGHT), , cross-join ( Cartesian product n*m rows returned) Exp: outer joint SELECT Employee. Name, Department. DeptName FROM Employee, Department WHERE Employee.Employee_ID = Department.Employee_ID; cross-join SELECT * FROM table1, table2; self join SELECT | |’ = e2.emp_no; ‘ | | e2.ename FROM emp e1, emp e2 WHERE e1. emp_no

The following summarizes the result of the join operations: The result of T1 INNER JOIN T2 consists of their paired rows where the join-condition is true. The result of T1 LEFT OUTER JOIN T2 consists of their paired rows where the join-condition is true and, for each unpaired row of T1, the concatenation of that row with the null row of T2. All columns derived from T2 allow null values. The result of T1 RIGHT OUTER JOIN T2 consists of their paired rows where the join-condition is true and, for each unpaired row of T2, the concatenation of that row with the null row of T1. All columns derived from T1 allow null values. The result of T1 FULL OUTER JOIN T2 consists of their paired rows and, for each unpaired row of T2, the concatenation of that row with the null row of T1 and, for each unpaired row of T1, the concatenation of that row with the null row of T2. All columns derived from T1 and T2 allow null values.

5. Q. How do you add record to a table? A. INSERT into table_name VALUES (‘ALEX’ , 33 , ‘M’); 6. Q. How do you add a column to a table? A. ALTER TABLE Department ADD (AGE, NUMBER); 7. Q. How do you change value of the field? A. UPDATE EMP_table set number = 200 where item_munber = ‘CD’; update name_table set status = 'enable' where phone = '4161112222'; update SERVICE_table set REQUEST_DATE = to_date ('2006-03-04 09:29', 'yyyy-mmdd hh24:MI') where phone = '4161112222'; 8. Q. What does COMMIT do? A. Saving all changes made by DML statements 9. Q. What is a primary key? A. The column (columns) that has completely unique data throughout The table is known as the primary key field. 10. Q. What are foreign keys? A. Foreign key field – is a field that links one table to another table’s primary or foreign key. 11. Q. What is the main role of a primary key in a table? A. The main role of a primary key in a data table is to maintain the internal integrity of a data table. 12. Q. Can a table have more than one foreign key defined? A. A table can have any number of foreign keys defined. It can have only One primary key defined. 13. Q. List all the possible values that can be stored in a BOOLEAN data field. A. There are only two values that can be stored in a BOOLEAN data field: -1(true) and 0(false). 14 Q. What is the highest value that can be stored in a BYTE data field? A. The highest value that can be stored in a BYTE field is 255. or from -128 to 127. Byte is a set of Bits that represent a single character. Usually there are 8 Bits in a Byte, sometimes more, depending on how The measurement is being made. Each Char requires one byte of memory

A2. WHERE PerDiemExpenses IS NULL C. Any data beyond the fourth place will be truncated by Visual Basic without reporting an error. Procedures do not return values they perform tasks. Q. you must use the keyword IS. Q. Q. The NULL is how SQL handles missing values. A trigger defines a set of actions that are performed in response to an insert. update. 19. When such an SQL operation is executed. WHERE PerDiemExpenses <> B. Q. Which of the following WHERE clauses will return only rows that have a NULL in the PerDiemExpenses column? A. What is a stored procedure? A. Allen B. The process of table design is called normalization. B is correct � When searching for a NULL value in a column. or delete operation on a specified table. 16. Q. 21. What is Trigger? A. Arifthmetic operation with NULL in SQL will return a NULL. 17. Q. in this case the trigger has been activated. WHERE PerDiemExpenses NOT IN (*) A. 22. No quotes are required around the keyword NULL. Referential integrity constraints are rules That are partnof the table in a database schema. How many places to the right of the decimal can be stored in a CURRENCY data field? A. Trigger will execute a block of procedural code against the database when a table event occurs. A. What is Normalization? A. A procedure is a group of PL/SQL statements that can be called by a name. 15. You issue the following query:SELECT FirstName FROM StaffListWHERE FirstName LIKE'_A%'Which names would be returned by this query? Choose all that apply. Q. Describe how NULLs work in SQL? A.And can have a value from 0 to 255 (or 0 to 11111111 in binary). CLARK . 18. 20. WHERE PerDiemExpenses = NULL D. What is referential integrity constraints? A. the CURRENCY data type can store up to four places to the right of the Decimal. Q.

and the percent sign (%) stands for any number of characters of any case including none. both of these values would have been returned. . Q. only strings with an uppercase "A" as their second letter are returned 23. if you want the data sorted in descending order. However. Q. SELECT LastName ||'. City AS "Home City" "FROM StudentsORDER BY "Student Name" 26. Therefore. Write SQL SELECT query that returns the first and last name of each instructor. Q. Because this string starts with an underscore rather than a percent sign. A. Salary FROM Instructors WHERE Salary > 5400 AND Salary < 6600. it won't return Allen or Clark because they represent zero and two characters before the "A". JACKSON David A. Write a SQL SELECT query that only returns each city only once from Students table? Do you need to order this list with an ORDER BY clause? A.' || FirstName. SELECT LastName ||'. Write SQL SELECT example how you limiting the rows returned with a WHERE clause. Q. The Distinct keyword automatically sorts all data in ascending order. Write a SQL SELECT sample of the concatenation operator. the Salary. you have to use an ORDER BY clause 24.C. The underscore (_) stands for any one character of any case. If the LIKE string had been "%A%". D. C is correct � Two wildcards are used with the LIKE operator. 25. City FROM Students. A. David was not returned because all non-wild card characters are case sensitive. How to rename column in the SQL SELECT query? A.' || FirstName AS "Student Name". 27. SELECT DISTINCT City FROM Students. SELECT InstructorID. Q.

LTRIM and RTRIM functions were included in earlier versions of Oracle. MIN C. Q. DD. FROM. To remove padded spaces. 29. Salary. numeric. Which of the following functions can be used only with numeric values? (Choose all that apply. Which function do you use to remove all padded characters to the right of a character value in a column with a char datatype? A. Which statement do you use to eliminate padded spaces between the month and day values in a function TO_CHAR(SYSDATE. WHERE. YYYY') 31.and gives each of them a number. The LENGTH function is a character function that returns the number of letters in a character value. ROWNUM FROM Instructors. Q. ORDER BY. RPAD C. LENGTH D. Only the SELECT and FROM clause are mandatory. A and D � Only A and D are correct. The ROUND function works with both numeric and date values. . HAVING. you use the "fm" prefix before the date element that contains the spaces. ROUND A. A. Q. The MIN function Works with any character. SELECT FirstName. 28.) A. LastName. TO_CHAR(SYSDATE. YYYY') ? A. Is the WHERE clause must appear always before the GROUP BY clause in SQL SELECT ? A. GROUP BY. TRIM A.'Month. SUM E. AVG B. or date datatype. Q. The proper order for SQL SELECT clauses is: SELECT.'fmMonth DD. RTRIM B. Yes. C � The TRIM function is used to remove padded spaces. but Oracle 8i has replaced them with a single TRIM function 30.

When Oracle executes a statement with nested subqueries.32. Shared locks are set on database resources so that many transactions can access the resource. 34. 37. Oracle has two lock modes: shared or exclusive. CREATE A. It is the outermost query that returns a result set. Oracle uses locking mechanisms to protect data from being destroyed by concurrent transactions. The INTERSECT operator returns only those rows that exist in both queries. Question. A and B � The INSERT and UPDATE statements are Data Manipulation Language (DML) commands. GRANT is a Data Control Language (DCL) command. The AS keyword is optional when specifying a column alias. Question. TRUNCATE E. INSERT B. You use the MINUS operator to return all rows from one query except where duplicate rows are found in a second query. UPDATE C. You must enclose the column alias in double quotes when the alias contains a space or lowercase letters. Exclusive locks are set on resources that ensure . Q. The UNION ALL operator returns all rows from both queries including duplicates. The UNION operator returns all rows from both queries minus duplicates. Q. Which operator do you use to return all of the rows? from one query except rows are returned in a second query? A. TRUNCATE and CREATE are Data Definition Language (DDL) commands 36. If you specify an alias in l owercase letters without double quotes. 35 Q. 33. GRANT D. How you will create a column alias? (Oracle 8i) A. What Oracle lock modes do you know? A. it always executes the innermost query first. How Oracle executes a statement with nested subqueries? A. What is Oracle locking? A. Which of the following statements are Data Manipulation Language commands? A. Q. This query passes its results to the next query and so on until it reaches the outermost query. the alias will appear in uppercase.

database manipulation interface.FILE_NUM order by j. software. and database control interface. Question. it consists from: BEGIN-TRANSACTION Name Code END TRANSACTION Name 42. database definition interface. Question.COMPANY_NAME = 'TEST6' AND j. Question.OFFICE_ID = '101' AND a. A database management system is composed of five elements: computer hardware.JOB_TYPE ='C' AND j. Explain SQL SELECT example: select j. and operations procedures. Query optimization is the part of the query process in which the database system compares different query strategies and chooses the one with the least expected cost 39.OFFICE_ID = '101' AND j.job j. What databases do you know? Informix DB2 SQL Oracle 43. concurrency control. people (users). What is query optimization? A. . A transaction is a collection of applications Code and database manipulation code bound into an indivisible unit of execution.FILE_NUM.ACTIVE_IND = 'Y' AND a. The database management system software includes components for storage management. Question. What is transaction? A.address a where j. What are the main components of Database management systems transaction has exclusive access to the database resource 38. Question. transaction processing. A. 40.ADDRESS_STATUS_ID = 'H' AND a.FILE_NUM from DB_name. 41. Question.FILE_NUM = j. What are the main attributes of database management system? A. DB_name. data.

Question. SQL comments are introduced by two consecutive hyphens . 44. Question: Describe SQL comments.QA 2) The AVG function tells you the average value of a numeric column. it accepts one parameter which is a column value or a string literal 45.QA 46. TO_NUMBER converts a character string containing digits to a numeric data type. What does DDL stand for? A. TO_CHAR converts a number / date to a string. Describe some Conversion Functions that you know A. DCL is Data Control Language statements. SELECT MIN(SALARY) FROM TESTING. 1) The COUNT function tells you how many rows were in the result set. DDL is Data Definition Language statements. A. What does DML stand for? A. Q. TO_DATE converts a string (representing a date) to a date. this is outer joint select statament from two tables. DML is Data Manipulation Language statements.QA 4) The SUM function tells you the sum value of a numeric column.QA 3) The MAX and MIN functions tell you the maximum and minimum value of a numeric column. Question.Answer: j and a aliases for table names. SELECT SUM(SALARY) FROM TESTING. Describe some Group Functions that you know A. (SELECT) 47. SELECT COUNT(*) FROM TESTING. (COMMIT) 49. (CREATE) 48. Question. What does DCL stand for? A. Q. SELECT MAX(SALARY) FROM TESTING.

A. FETCH FIRST clause 51. SELECT clause 6.member_role = '100' order by TB1. 52.TB_name2 TB2 where TB1. WHERE clause 3. Q. DB_name.num.program. The TO_DATE function returns a timestamp from a character string that has been interpreted using a character template. Describe TO_DATE function.bu_id. The clauses of the subselect are processed in the following sequence (DB2): 1. TB2.(--) and ended by the end of the line.TB_name1 TB1. However all new interview questions (regardless of there . TB1. The interview questions found above are listed in order of complexity. case TB1. 50. 'org') and TB1.member_id fetch first 30 rows only On this page I put some SQL interview questions. select TB1.program in ('com'. Q. Question: In the domain table we have status as a numeric value from 01 to 04 and we have text definition of these values in the design document. FROM clause 2. ORDER BY clause 7. These SQL interview questions are very simple and mainly were used for interviewing software testers who is involved in database SQL testing or grey box testing. (DB2) A. TB1. In what sequence SQL statement are processed? A. Write SQL query to see the result as a text definitions that is corresponded to these values. GROUP BY clause 4. TO_DATE is a synonym for TIMESTAMP_FORMAT. HAVING clause 5.status end from DB_name.member_id.status when '01' then 'Auto renew' when '02' then 'Expired' when '03' then 'Sold' when '04' then ‘Terminated’ else TB_name.

There are basically two types of indexes that we use with the SQL Server. UPDATE_STATISTICS updates the indexes on these tables accordingly. If we do a large amount of deletions any modification or Bulk Copy into the tables. This is a set of more than a hundred Microsoft SQL Server interview questions. Triggers is also similar to stored procedures. Some questions are open-ended. Clustered and the Non-Clustered. What is a trigger? .The difference is that. When do we use the UPDATE_STATISTICS command? . .If we have several tables in a db and we want to view only specific columns from specific tables we can go for views. What is the basic difference between clustered and a non-clustered index? .This command is basically used when we do a large processing of data. Its basically like a Macro so when you invoke the Stored procedure.Its nothing but a set of T-SQL statements combined to perform a single task of several tasks.Triggers are basically used to implement business rules. The difference is that it can be activated when data is added or edited or deleted from a table in a database. The leaf level of a clustered index is the actual data and the data is resorted in case of clustered index. What is a Stored Procedure? . an index on that db basically helps in the way the data is sorted to process the query for faster and data retrievals are much faster when we have an index. What is an Index? . Can you give an example of Stored Procedure? . What are cursors? .Well cursors help us to do an operation on a set of data that we retreive by commands such as Select columns from table. We can also have user defined stored procedures which can be called in similar way. This one always gets asked.When queries are run against a db.sp_helpdb . What is a view? . sp_who2. You can find more SQL interview questions searching the WEB. For example : If we have duplicate records in a table we can remove it by declaring a cursor which would check the records during retreival one by one and remove rows which have duplicate values. For a while the database interview questions were limited to Oracle and generic database design questions. Whereas in case of non-clustered index the leaf level is actually a pointer to the data in rows so we can have as many non-clustered indexes as we can on the db. you actually run a set of statements.difficulty) will be added to the bottom of the list. So the Process of organizing this data into tables is actually referred to as normalization. Clustered index is unique for any given table and we can have only one clustered index on a table.Well a relational database is basically composed of tables that contain related data. sp_renamedb are a set of system defined stored procedures. we need to basically update the indexes to take these changes into account. What are the types of indexes available with SQL Server? . It would also suffice the needs of security some times allowing specfic users to see only specific columns based on the permission that we can configure on the view. and some do not have answers. Views also reduce the effort that is required for writing queries to access specific columns every time. What is normalization? .

both on client and the server. Can we use Truncate command on a table which is referenced by FOREIGN KEY? .Collation is basically the sort order.No.SQL Server runs on port 1433 but we can also change it for better security. What do you mean by COLLATION? . Cross Join When do you use SQL Profiler? . From where can you change the default port? .DBCC stands for database consistency checker. What command do we use to rename a db? . What is the difference between a HAVING CLAUSE and a WHERE CLAUSE? Having Clause is basically used only with the GROUP BY function in a query. i. Can you give me some DBCC command options?(Database consistency check) .Join actually puts data from two or more tables into a single result set.To check that all pages in a db are correctly allocated.Which TCP/IP port does SQL Server run on? .Delete command removes the rows from a table based on the condition that we provide with a WHERE clause. WHERE Clause is applied to each row before they are part of the GROUP BY function in a query. DBCC SQLPERF . Can you explain the types of Joins that we can have with Sql Server? . . Truncate will actually remove all the rows from a table and there will be no data in the table after we run the truncate command. DBCC CHECKFILEGROUP . We use these commands to check the consistency of the databases. Can you link only other SQL Servers or any database servers such as Oracle? . Dictonary .e. What is a Join in SQL Server? . What is the use of DBCC commands? . Outer Join.DBCC CHECKDB . What is a Linked Server? .In such cases we can first bring to db to single user using sp_dboptions and then we can rename that db and then we can rerun the sp_dboptions command to remove the single user mode.sp_renamedb ‘oldname’ . validation task and status checks. ‘newname’ Well sometimes sp_reanmedb may not work you know because if some one is using the db it will not accept this command so what do you think you can do in such cases? .It gives report on current usage of transaction log in percentage.Ensures that tables in the db and the indexes are correctly linked.We can link any server provided we have the OLE-DB provider from Microsoft to allow a link. For Oracle we have a OLE-DB provider for oracle that microsoft provides to add it as a linked server to the sql server group.SQL Profiler utility allows us to basically track connections to the SQL Server and also determine activities such as which SQL Scripts are running. There are three types of sort order Dictionary case sensitive. Can you tell me the difference between DELETE & TRUNCATE commands? ..There are three types of joins: Inner Join. failed jobs etc.From the Network Utility TCP/IP properties –> Port insensitive and Binary. maintenance.Checks all tables file group for any damage.and DBCC CHECKALLOC . We cannot use Truncate command on a table with Foreign Key because of referential integrity.Linked Servers is a concept in SQL Server by which we can add other SQL Server to a Group and query both the SQL Server dbs using T-SQL Statements..

First check the processor and memory usage to see that processor is not above 80% utilization and memory not above 40-45% utilization then check the disk utilization using Performance Monitor.First I will look to ensure that port settings are proper on server and client Network utility for connections. What are the different types of joins and what dies each do? What are the four main query statements? What is a sub-query? When would you use one? What is a NOLOCK? What are three SQL keywords used to change or set someone’s permissions? What is the difference between HAVING clause and the WHERE clause? What is referential integrity? What are the advantages of it? .Which stored procedure will you be running to add a linked server? . SQL AGENT SERVICE. What is BCP? When do we use it? . From Enterprise Manager we can configure the logshipping. sp_addlinkedsrvlogin What are the OS services that the SQL Server installation adds? . Secondly.SQL SERVER . Makepipe is run on Server and readpipe on client to check for any connection issues. If one server fails. Let us say the SQL Server crashed and you are rebuilding the databases including the master database what procedure to you follow? .We have to write some DTS packages for it. Where do you think the users names and passwords will be stored in sql server? .MS SQL SERVER SERVICE. How do you troubleshoot? .Windows mode and mixed mode (SQL & Windows).For restoring the master db we have to stop the SQL Server first and then from command line we can type SQLSERVER –m which will basically bring it into the maintenance mode after which we can restore the master for automation such as Jobs.They get stored in master db in the sysxlogins table.Enterprise Editions. But it won’t copy the structures of the same. DB Maintanance.Logshipping is a new feature of SQL Server 2000. What should we do to copy the tables.0 . schema and views from one SQL Server to another? .(I am not for running the databases SQL AGENT .but I think we have a command to do it). Backups DTC . ODBC is properly configured at client end for connection ——Makepipe & readpipe are utilities to check for connection. What is log shipping? Can we do logshipping with SQL Server 7. What are the authentication modes in SQL Server? .sp_addlinkedserver. In logshipping the transactional log file from one server is automatically updated into the backup database on the other server. Now you have to rebuild the db so what kind of action do you take? . Third would be to run UPDATE_STATISTICS command to update the indexes Lets say due to N/W or Security issues client is not able to connect to server or vice versa. DTC (Distribution transac co-ordinator) Can you explain the role of each service? . We should have two SQL Server .BulkCopy is a tool used to copy huge amount of data from tables and views. Let us say master db itself has no backup.Is for linking and connecting to other SQL Servers How do you troubleshoot SQL Server if its running very slow? . use SQL Profiler to check for the users and current SQL activities and jobs running which might be a problem. the other server will have the same db and we can use this as the DR (disaster recovery) plan.

What is database normalization? Which command using Query Analyzer will give you the version of SQL server and operating system? Using query analyzer.2nd Normal form or 3rd normal form? Why? Can we rewrite subqueries into simple select statements or with joins? Example? What is a function? Give some example? What is a stored procedure? Difference between Function and Procedure-in general? Difference between Function and Stored Procedure? Can a stored procedure call another stored procedure.? How do you find the number of rows in a table? Difference between Cluster and Non-cluster index? What is a table called. but today it takes 6 minutes” What is an execution plan? When would you use it? How would you view the execution plan? What is the STUFF function and how does it differ from the REPLACE function? What does it mean to have quoted_identifier on? What are the implications of having it off? What are the different types of replication? How are they used? What is the difference between a local and a global variable? What is the difference between a Local temporary table and a Global temporary table? How is each one used? What are cursors? Name four types of cursors and when each one would be applied? What is the purpose of UPDATE STATISTICS? How do you use DBCC statements to monitor various aspects of a SQL server installation? How do you load large data to the SQL server database? How do you check the performance of a query and how do you optimize it? How do SQL server 2000 and XML linked? Can XML be used to access data? What is SQL server agent? What is referential integrity and how is it achieved? What is indexing? What is normalization and what are the different forms of normalizations? Difference between server. RDBMS? Explain basic SQL queries with SELECT from where Order By. Group By-Having? . if it does not have neither Cluster nor Non-cluster Index? Explain DBMS. name 3 ways you can get an accurate count of the number of records in a table? What is the purpose of using COLLATE in a query? What is a trigger? What is one of the first things you would do to increase performance of a query? For example. If yes what level and can it be controlled? Can a stored procedure call itself(recursive). a boss tells you that “a query that ran yesterday took 30 seconds.transfer and server.execute method? What id de-normalization and when do you do it? What is better . If yes what level and can it be controlled.

Availability. how can you know the number of rows effected by last SQL statement? How can you get @@error and @@rowcount at the same time? What are sub-queries? Give example? In which case sub-queries are not feasible? What are the type of joins? When do we use Outer and Self joins? Which virtual table does a trigger use? How do you measure the performance of a stored procedure? Questions regarding Raiseerror? Questions on identity? If there is failure during updation of certain rows. given a set of numbers in column? If a stored procedure is taking a table data type. set commands? Explain what are db_options used for? What is the basic functions for master.Explain the basic concepts of SQL server architecture? Explain couple pf features of SQL server Scalability. where are unique creates a nonclustered index by default. but unique key allows one NULL only.0 and 7. Another major difference is that. etc.5 to 7. Integration with internet.0 to 2000? What is data integrity? Explain constraints? Explain some DBCC commands? Explain sp_configure commands. how it looks? How m-m relationships are implemented? How do you know which index a table is using? How will oyu test the stored procedure taking two parameters namely first name and last name returning full name? How do you find the error. msdb. tempdb databases? What is a job? What are tasks? What are primary keys and foreign keys? How would you Update the rows which are divisible by 10. How to find 6th highest salary from Employee table . But by default primary key creates a clustered index on the column. primary key doesn’t allow NULLs. what will be the state? What’s the difference between a primary key and a unique key? Both primary key and unique enforce uniqueness of the column on which they are defined.)? Explain fundamentals of Data ware housing & OLAP? Explain the new features of SQL server 2000? How do we upgrade from SQL Server 6.

RIGHT OUTER JOINS and FULL OUTER JOINS. primary key doesn't allow NULLs. In all these tables it should be varchar(8). i. One-to-Many relationships are implemented by splitting the data into two tables with primary key and foreign key relationships. one of them will become the primary key. What is the Referential Integrity? Referential integrity refers to the consistency that must be maintained between primary and foreign keys. It will be a good idea to read up a database designing fundamentals text book What's the difference between a primary key and a unique key? Both primary key and unique enforce uniqueness of the column on which they are defined. . If the table has more than one candidate key. there is a column called Flight_Num which appears in many tables. Generally a candidate key becomes the primary key of the table. TRUNCATE TABLE can be rolled back. What are user defined datatypes and when you should go for them? User defined datatypes let you extend the base SQL Server datatypes by providing a descriptive name. Many-to-Many relationships are implemented using a junction table with the keys from both the tables forming the composite primary key of the junction table. in your database. alternate key. and the rest are called alternate keys. OUTER JOINs. one-to-many and many-to-many relationships while designing tables? One-to-One relationship can be implemented as a single table and rarely as two tables with primary and foreign key relationships. 4. What's the difference between DELETE TABLE and TRUNCATE TABLE commands? DELETE TABLE is a logged operation. Untill SQL Server 6. See CREATE DEFUALT in books online. but nique key allows one NULL only. . 3. every foreign key value must have a corresponding primary key value What is the row size in SQL Server 2000? 8060 bytes. Define candidate key. which makes it slow.5 bit datatype could hold either a 1 or 0 and there was no support for NULL.SELECT TOP 1 salary FROM (SELECT DISTINCT TOP 6 salary FROM employee ORDER BY salary DESC) a ORDER BY salary What is a join and List different types of joins Joins are used in queries to explain how different tables are related. IDENTITY columns and timestamp columns can't have defaults bound to them. OUTER JOINs are further classified as LEFT OUTER JOINS. Another major difference is that. and format to the database. Types of joins: INNER JOINs. where are unique creates a nonclustered index by default.e. 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. But by default primary key creates a clustered index on the column. which makes it faster. CROSS JOINs. In this case you could create a user defined datatype called Flight_num_type of varchar(8) and use it across all your tables. 2. if no value is supplied to that column while inserting data. What is bit datatype and what's the information that can be stored inside a bit column? Bit datatype is used to store boolean information like 1 or 0 (true or false). so the deletion of each row gets logged in the transaction log. 6. composite key. How do you implement one-to-one.0 onwards. A candidate key is one that can identify each row of a table uniquely. Joins also let you select data from a table depending upon data from another table. TRUNCATE TABLE also deletes all the rows in a table. which is NULL. instead it logs the deallocation of the data pages of the table. but it won't log the deletion of each row. But from SQL Server 7. bit datatype can represent a third state. Of course. Take for example. 5. A key formed by combining at least two or more columns is called composite key.

What are the new features introduced in SQL Server 2000 (or the latest release of SQL Server at the time of your interview)? What changed between the previous version of SQL Server and the current version? This question is generally asked to see how current is your knowledge. 13. For more information and explanation of these properties. These are the properties of a transaction. at least be familiar with the way clustering works and the two clusterning configurations Active/Active and Active/Passive. Serializable. which lets you customize the isolation level at the connection level. 8. See SQL Server books online for an explanation of the isolation levels. page locks) into higher level locks (like table locks).5. instead it logs the deallocation of the data pages of the table. Check out SQL Server books online for the page titled: "Maximum Capacity Specifications". 9. TRUNCATE TABLE can be rolled back.0 onwards it's dynamically managed by SQL Server. What is a transaction and what are ACID properties? A transaction is a logical unit of work in which. Explain the storage models of OLAP Check out MOLAP. Here are the other isolation levels (in the ascending order of isolation): Read Uncommitted. Don't be surprised with questions like 'what is the maximum number of columns per table'. which makes it faster. CREATE INDEX myIndex ON myTable(myColumn) What type of Index will get created after executing the above statement? Non-clustered index. Explain Active/Active and Active/Passive cluster configurations Hopefully you have experience setting up cluster servers. What is lock escalation? Lock escalation is the process of converting a lot of low level locks (like row locks. But if you don't. TRUNCATE TABLE also deletes all the rows in a table. Of course. 1. Constraints enable the RDBMS enforce the integrity of the database automatically.Repeatable Read. Durability. Also check out the section titled "Backward Compatibility" in books online which talks about the changes that have taken place in the new ersion. Generally there is a section in the beginning of the books online titled "What's New". 10. see SQL Server books online or any RDBMS fundamentals text book. which has all such information. but from SQL Server 7. rule or defaults. 14. Explain the architecture of SQL Server This is a very important question and you better be able to answer it if consider yourself a DBA. To prevent this from happening. SQL Server escalates the many fine-grain locks to fewer coarse-grain locks. you should have tried those things to better answer the questions. SQL Server books online has enough information on this topic and there is a good white paper available on Microsoft site. all the steps must be performed or none. Isolation. PRIMARY KEY. but it won't log the deletion of each row. 11. Every lock is a memory structure too many locks would mean. without needing you to create triggers. Explain different isolation levels An isolation level determines the degree of isolation of data between concurrent transactions. CHECK. which makes it slow. Read up the chapter dedicated to SQL Server Architecture. so the deletion of each row gets logged in the transaction log. unless specified otherwise. ACID stands for Atomicity. FOREIGN KEY . Be sure to read about SET TRANSACTION ISOLATION LEVEL. 12. Types of constraints: NOT NULL. 16. Read Committed. What are constraints? Explain different types of constraints. What's the maximum size of a row? 8060 bytes.7. reading just that is not enough. UNIQUE. 15. The efault SQL Server solation level is Read Committed. Important thing to note: By default a clustered index gets created on the primary key. What's the difference between DELETE TABLE and TRUNCATE TABLE commands? DELETE TABLE is a logged operation. Consistency. Of course. SQL Server books online is the best place to read about SQL Server architecture. ROLAP and HOLAP in SQL Server books online for more infomation. more memory being occupied by locks. Lock escalation threshold was definable in SQL Server 6.

The row located could be the RID or the Clustered index key. A livelock also occurs when read transactions monopolize a table or page. if you are tasked with securing an SQL Server? Again this is another open ended question. with the leaf level nodes having the index key and it's row locater. MSDN has some information about RAID levels and for detailed information. enabling auditing. table scans. What are the steps you will take to improve performance of a poor performing query? This is a very open ended question and there could be a lot of reasons behind the poor performance of a query. attempt to acquire a lock on the other's piece. 6. fault tolerance. "ALTER TABLE" Whar is an index? What are the types of indexes? How many clustered indexes can be created on a table? I create a separate index on each column of a table. setting up firewalls. poorly written query with unnecessarily complicated joins. If you create an index on each column of a table. all the rows in the table are stored in the order of the clustered index key. SET STATISTICS IO ON. What is RAID and what are different types of RAID configurations? RAID stands for Redundant Array of Inexpensive Disks. as the query optimizer can choose from all the existing indexes to come up with an efficient execution plan. Each process would wait indefinitely for the other to release the lock. Indexes are of two types. indexes need disk space. what are the advantages and disadvantages of this approach? Indexes in SQL Server are similar to the indexes in books. SQL Server detects deadlocks and terminates one user's process. excess recompilations of stored procedures. all the indexes need to be updated. SET SHOWPLAN_TEXT ON. 4. At the same t ime. there can be only one clustered index per table. check out the RAID advisory board's homepage. forcing a write transaction to wait indefinitely. too much normalization. where a request for an exclusive lock is repeatedly denied because a series of overlapping shared locks keeps interfering. 5. 3. blocking. depending up on the absence or presence of clustered index on the table.2. Another disadvantage is that. They help SQL Server retrieve the data quicker. isolating SQL Server from the web server etc. SQL Server Profiler. each having a lock on one piece of data. Windows NT /2000 Performance monitor. unless one of the user processes is What are the steps you will take. more disk space is used. excess usage of cursors and temporary tables. databse and application roles to control access to the data. Don't forget to check out sql-server-performance. Non-clustered indexes are stored as B-tree structures (so do clustered indexes). using server. securing the physical database files using NTFS permissions. What is a deadlock and what is a live lock? How will you go about resolving deadlocks? Deadlock is a situation when two processes. Some of the tools/ways that help you troubleshooting performance problems are: SET SHOWPLAN_ALL ON. Here are some things you could talk about: Preferring NT authentication. When you craete a clustered index on a table. DELETE) will become slow. using multiprotocol encryption. Clustered indexes and non-clustered indexes. data modification operations (such as INSERT. There are six RAID levels 0 through 5 offering different levels of performance. renaming the Administrator account on the SQL Server computer. Non-clustered indexes have their own storage separate from the table data storage. missing or out of date statistics. But some general issues that you could talk about would be: No indexes. used to provide fault tolerance to database servers. as every time data changes in the table. UPDATE. using an unguessable SA password. For an explanation of these constraints see books online for the pages titled: "Constraints" and "CREATE TABLE". SQL Server detects the situation after four denials and refuses further shared locks. the more indexes you have. it improves the query performance. procedures and triggers without SET NOCOUNT ON. . Download the white paper on performance tuning SQL Server from Microsoft web site. So. Graphical execution plan in Query Analyzer. A livelock is one. restricting physical access to the SQL Server. setting up SSL. disabling the Guest account.

Read up the following topics in SQL Server books online: Understanding and avoiding blocking. Coding efficient transactions. How to restart SQL Server in single user mode? How to start SQL Server in minimal configuration mode? SQL Server can be started from command line. you have to choose your option depending upon your requirements. SQL Server supports the following types of replication scenarios: . BCP. sp_autostats. If an indexed column has unique values then the selectivity of that index is more. using the SQLSERVR. 11. Check out the BACKUP and RESTORE commands in SQL Server books online. But there are a whole load of DBCC commands which are very useful for DBAs.0+ are Full database backup. DBCC SHOW_STATISTICS. This forces the second connection to wait. SELECT. 10. DBCC SHOWCONTIG. sp_updatestats 12.. dettaching and attaching databases.SELECT. creating INSERT scripts to generate data.Be prepared to write the commands in your interview. how would you go about choosing a backup plan? Types of backups you can create in SQL Sever 7.EXE. replication. -m is used for starting SQL Server in single user mode and -f is used to start the SQL Server in minimal confuguration mode. filegroup backup. 14. DBCC CHECKTABLE. But what if you have to create a database with two filegroups. how do you update them? Statistics determine the selectivity of the indexes. This EXE has some very important parameters with which a DBA should be familiar with. Query optimizer uses these indexes in determining whether to choose an index or not while executing a query. DBCC SHRINKFILE etc. if the distribution of key values has changed). DBCC CHECKCATALOG. or the table has been truncated using the TRUNCATE TABLE statement and then repopulated 3) Database is upgraded from a previous version Look up SQL Server books online for the following commands: UPDATE STATISTICS. changed. sp_createstats. Explian different types of BACKUPs avaialabe in SQL Server? Given a particular scenario. CREATE STATISTICS. What are the different ways of moving data/databases between servers and databases in SQL Server? There are lots of options available. Books online also has information on detailed backup/restore architecture and when one should go for a particular kind of backup. 13. What is database replicaion? What are the different types of replication you can set up in SQL Server? Replication is the process of copying/moving data between databases on the same or different servers. STATS_DATE. DROP STATISTICS. What are statistics. logshipping. Some situations under which you should update statistics: 1) If there is significant change in the key values in the index 2) If a large amount of data in an indexed column has been added.. what are the DBCC commands that you commonly use for database maintenance? DBCC CHECKDB.. as opposed to an index with non-unique values. DBCC SHRINKDATABASE. Check out SQL Server books online for more parameters and their explanations.. Check out SQL Server books online for more information. As a part of your job.INTO. Check out SQL Server books online for more information. one on drive C and the other on drive D with log on drive E with an initial size of 600 MB and with a growth factor of 15%? That's why being a DBA you should be familiar with the CREATE DATABASE syntax. DTS. Also check out the article Q169960 from Microsoft knowledge base. Explain CREATE DATABASE syntax Many of us are used to craeting databases from the Enterprise Manager or by just issuing the command: CREATE DATABAE MyDB. blocked on the first. or removed (that is. under what circumstances they go out of date. DBCC CHECKALLOC. INSERT. Check out SET DEADLOCK_PRIORITY and "Minimizing Deadlocks" in SQL Server books online.7. 9. 8. differential database backup. transaction log backup. 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. Some of the options you have are: BACKUP/RESTORE.

7000 hike Salary between 55000 and 65000 -. What are cursors? Explain different types of cursors. . Forward-only. To know more about this process visit 16. But the same can be achieved by multiple update statements or can be combined in a single UPDATE statement as shown below: UPDATE tbl_emp SET salary = CASE WHEN salary BETWEEN 30000 AND 40000 THEN salary + 5000 WHEN salary BETWEEN 40000 AND 55000 THEN salary + 7000 WHEN salary BETWEEN 55000 AND 65000 THEN salary + 10000 END Another situation in which developers tend to use cursors: You need to call a stored procedure when a column in a particular row meets certain condition. Types of cursors: Static. as long as there is a unique key to identify each row. Joins also let you select data from a table depending upon data from another table. See books online for more information. You don't have to use cursors for this. which is used to determine the service pack installed. What is a join and explain different types of joins. set based operations can be used instead of cursors. 15. This can be achieved using WHILE loop. Most of the times. however large the resultset is. Here is an example: If you have to give a flat hike to your employees using the following criteria: Salary between 30000 and 40000 -.o o o Snapshot replication Transactional replication (with immediate updating subscribers. 17. How to determine the service pack currently installed on SQL Server? The global variable @@Version stores the build number of the sqlservr. Joins are used in queries to explain how different tables are related. Write down the general syntax for a SELECT statements covering all the options. it results in a network roundtrip. SELECT select list [INTO new_table_] FROM table_source [WHERE search_condition] [GROUP BY group_by_expression] [HAVING search_condition] [ORDER BY order_expression [ASC | DESC] ] 18. determine each employee's salary and update his salary according to the above formula.Keyset-driven. Cursors are also costly because they require more resources and temporary storage (results in more IO operations).exe. where as a normal SELECT query makes only one rowundtrip.9000 hike In this situation many developers tend to use a cursor. Furthere. there are restrictions on the SELECT statements that can be used with some types of cursors. Be prepared to explain how different replication agents function. Dynamic. Here's the basic syntax: (Also checkout SELECT in books online for advanced syntax). what are the main system tables used in replication etc. What are the disadvantages of cursors? How can you avoid cursors? Cursors allow row-by-row prcessing of the resultsets. Disadvantages of cursors: Each time you fetch a row from the cursor.5000 hike Salary between 40000 and 55000 -. with queued updating subscribers) Merge replication See SQL Server books online for indepth coverage on replication.

OUTER JOINs. as constraints are much faster. What is the system function to get the current user's user id? USER_ID(). in an OLTP system. auditing. SUSER_SID(). sp_OAGetProperty. USER. 19. Search SQL Server 2000 books online for INSTEAD OF triggers. very much. use constraints for this purpose. sp_OADestroy.0. 24.0 there's no way to control the order in which the triggers fire. one for UPDATE and one for DELETE. Also check out books online for 'inserted table'. you need a self join. Triggers can also be used to extend the referential integrity checks.Also check out other system functions like USER_NAME(). UPDATE or DELETE operation takes place on a table. HOST_NAME(). CREATE TABLE emp ( empid int. What are triggers? How many triggers you can have on a table? How to invoke a trigger on demand? Triggers are special kind of stored procedures that get executed automatically when an INSERT. this restriction is gone. ROLLBACK. 22. In SQL Server 2000 you could specify which trigger fires first or fires last using sp_settriggerorder Triggers can't be invoked on demand. So in a way. 21. triggers fire only after the data modification operation happens. For more information see pages from books online titled: "Join Fundamentals" and "Using Joins". instead of triggers. There is a trigger defined for INSERT operations on a table. But in SQL Server 2000 you could create pre triggers also. DELETE) happens on the table on which they are defined. RIGHT OUTER JOINS and FULL OUTER JOINS. Yes. CURRENT_USER. Triggers are generally used to implement business rules.OUTER JOINs are further classified as LEFT OUTER JOINS. What do you think of this implementation? Can this be implemented better? Instantiating COM objects is a time consuming process and since you are doing it from within a trigger. it slows down the data insertion process. Same is the case with sending emails from triggers. sp_OASetProperty. and you could create multiple triggers per each action. The trigger is written to instantiate a COM object and pass the newly insterted rows to it for some custom processing. 'deleted table' and COLUMNS_UPDATED() 23. Here is an example: Employees table which contains rows for normal employees as well as managers. you can instantiate a COM (written in languages like VB.5 you could define only 3 triggers per table.just the way we call normal stored procedures using the EXEC statement. . This scenario can be better implemented by logging all the necessary data into a separate table. except that two instances of the same table will be joined in the query. But in 7. Check out BEGIN TRAN. CROSS JOINs. Also see books online for sp_OAMethod. Can you have a nested transaction? Yes. and have a job which periodically checks this table and does the needful. C++ using Open Data Services (ODS) API) that can be called from TSQL. Till SQL Server 7. What is a self join? Explain it with an example.Types of joins: INNER JOINs. one for INSERT. 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. they are called post triggers.0 onwards. In SQL Server 6. They get triggered only when an associated action (INSERT. So. UPDATE. Self join is just like any other join. to find out the managers of all the employees. From SQL Server 7. VC++) object from T-SQL by using sp_OACreate stored procedure. COMMIT. SYSTEM_USER. See books online to learn how to create extended stored procedures and how to add them to SQL Server. but wherever possible. SESSION_USER. SAVE TRAN and @@TRANCOUNT 20.

allows you to retrieve information easily whenever and in whichever format it is desired.mgrid = t2.'Vyas' 2. They also have elaborate database administration for handling .empid A DBMS (DataBase Management System) is used to store data.Relational Database Management Systems The functionality of RDBMS is the same as DBMS except that the features offered for data storage and retrieval are very advanced. which means it stores data in tables with rows and columns.empname [Employee]. besides allowing you to store large amounts of data. emp t2 WHERE t1.empname. empname char(10) ) INSERT INSERT INSERT INSERT INSERT emp emp emp emp emp SELECT SELECT SELECT SELECT SELECT 1.NULL.mgrid int. In addition to this Oracle can also store data as XML or Objects. Storing this data in a way to facilitate easy access is very important and that is why computers are used in organizations. Excellent security features are offered by these systems. This is possible using DBMS. t2. Oracle is an Object Relational Database. It also requires tedious clerical hours to arrange the data in the form required by top management.2. RDBMS . For example.2. especially.empname [Manager] FROM emp t1.mgrid = t2.'Sourabh' SELECT t1. DBMS. These systems are based on mathematical SET theory. 2. An object database will store data as objects.'Shobha' 4.'Mohan' 3.2.'Shridhar' 5. DBMS .3. 'No manager') [Manager] FROM emp t1 LEFT OUTER JOIN emp t2 ON t1. COALESCE(t2. one gets different types of databases that stores and manages data differently. Likewise. A RDBMS ensures that the data stored in the database is accurate and relevant. These systems have capability to store a very large amount of data and have quick data retrieval mechanisms. RDBMS packages are used in medium to large-scale organizations. a Relational DBMS (or RDBMS) stores data as relations (rows and columns). a hierarchical database will store data in complex structures linked with pointers.Database Management Systems Companies need to process a large amount of data. Manual storage of this data wastes a lot of time while retrieving it.empname [Employee]. Nevertheless.empid Here's an advanced query using a LEFT OUTER JOIN that even returns the employees without managers (super bosses) SELECT t1. those where data has to be made available on distributed networks.

To create a complete application. With DBMS. one can develop a complete application. starting from processing inputs to generating output.multi-users. one requires client software like VB. 3. and failures. This is a standard language commonly used across different RDBMS. An RDBMS uses SQL (Structures Query Language) to access data from database. where security of the data is not of major concern. Also DBMS are not necessarily client server based systems. What is the difference between RDBMS & DBMS? DBMS are for smaller organizations with small amount of data. RDBMS are designed to take care of large amounts of data and also the security of this data. storage. Developer 2000 . They are also client server based systems.