SQL Interview Questions (Set-1)

This is our first set of SQL interview Questions.

Prepare well and crack your dream job. It is said,“Fall seven times, stand up eight.”(Japanese proverb), so work hard to achieve heights.

Work hard to crack SQL interview
Work Hard

Follow us on Facebook for more updates and learning!!!

  1. What are various types of SQL statements?
  2. What is the difference between Truncate, Drop and Delete?
  3. Difference between Local and Global Temp tables?
  4. What are indexes and types of indexes?
  5. How to copy only structure of Table A to Table B?
  6. Meaning of BCP in SQL?


a. Data definition language
  1. Create
  2. Alter
  3. Drop
  4. Truncate

b. Data Manipulation language 
  1. Select
  2. Insert
  3. Delete
  4. Update

c. Data Control Language
  1. Grant 
  2. Revoke

d. Transaction control statements
  1. Commit
  2. Rollback
  3. Save point 

2. Delete, is used to remove rows from a table, we can use where clause to limit the rows to be deleted. After delete we need to perform Commit or Rollback operation to make the changes permanent, thus we can say we have chance to undo the delete operation .It is a DML command. Delete will cause delete triggers on the table to be fired.

Truncate, it is used to remove all rows from a table. The operation cannot be rolled back and no triggers are fired. It is a DDL command and faster as It does not use the concept of undo operation thus even logs are not maintained for the deleted data.

Drop, is more dangerous as it removes table from the database unlike above commands which were only removing rows from the table. Like truncate it cannot be rolled back and no triggers are fired in this case, further this also a DDL command.

3. Temporary tables (temdb) are automatically deleted when they are not in use. 
  1. Local, It is prefixed with  single ‘#’ when while creation. Like create table #Study(ID int not null). Further they are available only to the connection that creates it and are deleted when the connection is closed. We can create a same local temp table with the same name but in a different connection.
  2. Global, It is prefixed by ‘##’ values, like create table ##Study (ID int not null).They are visible to all the connections of SQL server and are destroyed only when the last connection referencing the table is closed.

4Index: – It is an structure associated with a table or view which speed up the query retrieval time. An index contains keys which are combination of one or more columns of table or view. These keys are stored in B-Tree structure for efficient search of data from a table.

Clustered Index:- Example like phone directory, where each entry in the directory represents one row of the table. A table can have only one clustered index.
Non Clustered Index: – Example , index at the back of the book, where indexed values contains pointers to the actual rows(page number in a book).

Syntax:-Create index (index name) ON table_Name (Column name)

5. Select * into TableB from TableA where 0=1

6. BCP (Bulk copy Program) is a command line utility to bulk copy data between an SQL server and a data file (both in or out).We can use table or query to export/import data. Example we need to move data from database A to file B , so we would write bcp database A .TABLE A out file B.

Leave a Reply

Your email address will not be published. Required fields are marked *