Wednesday, January 11, 2012

SQL Interview Questions - A Complete Reference

1.   What is SQL??
Ans: SQL Stands for ‘Structured Query Language’
2.   What is Select statement?
Ans: Select statement is used for data retrieval purpose. The Select statement lets you select a set of values from a table in a database and the values selected from the database table would depend on the various conditions that are specified in the SQL query.
3.   How can you compare a part of the name rather than the entire name?
Ans: SELECT * FROM dbo.People WHERE Empname LIKE ‘%ab%’
Would return a recordset with records consisting Empname the sequence 'ab' in Empname
4.   What is the use of INSERT statement?
Ans: The INSERT statement lets you insert information into the database.
5.   How do you delete a record from table?
Ans: By using DELETE statement and WHERE clause.
6.   How could I get distinct entries in a table?
Ans: The SELECT statement in conjunction with DISTINCT lets you select a set of distinct values from a table in a database. The values selected from the database table would of course depend on the various conditions that are specified in the SQL query.
Example: SELECT DISTINCT Empname FROM Emptable
7.   How to get the results of a Query sorted in any order?
Ans: You can sort the results and return the sorted results to your program by using ORDER BY keyword.
Example: SELECT Empname, Age, City FROM Emptable ORDER BY Empname
8.   How can I find the total number of records in a table?
Ans: You could use the COUNT keyword
Example: SELECT COUNT (*) FROM Emp WHERE Age>40
9.   What is a join and explain different types of joins?
Ans: Joins are used in queries to explain how different tables are related and also let you select data from a table depending upon data from another table.
Types of joins: INNER JOINs, OUTER JOINs, CROSS JOINs. OUTER JOINs are further classified as LEFT OUTER JOINS, RIGHT OUTER JOINS and FULL OUTER JOINS.
10.  What is a self join?
        Ans: Self join is just like any other join, except that two instances of the same table will be joined in the              
        query.

Yet to be continued.. will refresh daily at a count of 5-10!!

No comments:

Post a Comment