This page contains SQL Server Developer Interview Questions. I would be adding many questions and answers from time to time, I suggest you to bookmark it, I’m sure you will have lots of Interview questions that are useful for your Interview preparation.
1. Can you write a SELECT statement without FROM Clause?
- Yes you can write a SELECT statement without having a FROM Clause.
SELECT ‘HELLO WORLD’
2. What are the different constraints in SQL Server?
- Primary Key Constraint.
- Foreign Key Constraint.
- Unique Key Constraint.
- Default Constraint.
- Check Constraint.
3. How do you display only few # of rows from any table?
- You can use TOP Clause to return only the # of rows from an underlying table.
4. What are the enhancements in SQL Server 2005 over SQL Server 2000 from a developer’s stand point?
- The below is a list of enhancements in SQL Server 2005 from a developer’s point of view.
- Common Table Expressions (CTE)
- Covering Indexes.
- EXCEPT and INTERSECT
- PIVOT and UNPIVOT
5. How will you rename a database or a database Object using T-SQL?
- Using SP_Rename system stored procedure you can rename a database object such as a table, view, stored procedure etc. Using SP_RenameDB you can rename a database. For more information read one of my blogs on this topic — Renaming database and database objects using T-SQL
6. What is the benefit of WHERE Clause?
- WHERE clause helps in filtering the rows that are affected by the query by using one or more conditions. Look at the following blog for examples to learn about Where clause. http://learnsqlwithbru.com/2010/06/25/using-where-clause-in-sql-server-query/
7. How can you display the top n no. of records in a table based on a column?
- It is possible to return such a result-set by using Top n clause along with Order By the column name.
8. How many Clustered and Non-Clustered Indexes can be created on a sinlge table?
- A table can contain a single Clustered Index at any time, where as the limit for Non-Clustered Indexes is 249. SQL Server 2008 supports upto 999 Non-Clustered Indexes.
9. How many columns can be created in a single table?
- A normal table, can contain 1024 columns and wide table can contain 30,000 columns per table.
10. What are constraints? What are the different constraints in SQL Server?
- Constraints are the way using which we can enforce and maintain database Integrity.
- Primary Key, Foreign Key, Unique, Check, Not Null are the various Constraints available in SQL Server.
11. What is the difference between Inner Join and Outer Join?
Inner Joins return the matching records in both the tables so the result set displays only the data that is matching in both the tables on the joining condition. Where as the result set in an Outer Join displays the matching data in both tables along with data from one of the tables where there is no matching records. The table from which additional data is to be displayed is based on the Right or Left Outer Join.
12. What is difference between Primary Key and Unique Key?
- Primary Key and Unique Key ensures that all the records are unique with the exception that a Unique Key constraint allows a single null value where as a Primary Key constraint does not allow null value.
- Multiple Unique Key constraints can be defined on a single table where as a only 1 Primary Key constraint can be defined.
13. What is the functionality of UNION in a T-SQL statement?
- UNION Operator combines data from two or more result sets and displays one final result set. The columns in the result sets should match in all of the result sets. UNION does not display duplicate rows (if there are any).
Added on Dec 7th 2011
14. What is the functionality of UNION ALL in a T-SQL statement?
- UNION ALL operator combines data from two or more result sets and displays one final result set including duplicate records. The columns in the result sets should match in all of the result sets. (Thanks to Ash posting a comment and bringing my notice about the mistake, it is corrected now)…
15. What is the difference between a Delete and Truncate?
- Delete is a logged operation, by that every record that is deleted is written / logged in the Transaction Log of the database, there by enabling the user to recover what was deleted. A Delete statement can be controlled by using a filtering condition, using “WHERE” clause.
- Truncate deletes the entire data of the table by deleting all the data pages of the table. It does not write in the log files, so it is quite fast, also it is not possible to recover the data using the Log backups, the only possibility is to recover back before the Truncate was run, using any and all kinds of available backups.
16. What is the difference between a Truncate Table and Drop Table?
- Truncate deletes the entire data in a table, but the table structure is still intact, the Indexes, constraints etc are all still available.
- Drop table deletes the table itself, resulting that the table and the underlying indexes, constraints etc are also deleted.
Feedback and comments are appreciated. That is the only way I know this blog was helpful to you and it motivate me to write more.
Email me at email@example.com
– Bru Medishetty