Top 50 SQL Interview Questions and answer

 

 

11.What is Cursor

Cursors enable manipulation of whole result sets at once.

 

12. What is subquery in sql

Subquery is nothing but a query within query, In which inner query execute first and then main query.

 

13.Types of subquery

There are two types of subquery
correlated subquery and non-correlated i.e subquery
Correlated subquery is dependent query, which we can write in from clause.
And it depend on execution of main query.
Where as subquery executes first and provide output as input to main query.

 

14.What is a constraint?

It is used to specify rule for data in a table.
It enforce business rule in table.

 

15.What are types of constraint

NOT NULL.
CHECK.
UNIQUE.
PRIMARY KEY.
FOREIGN KEY.

 

16.If we create primary key, which index will be created?

cluster index.

 

17.What is Self-Join?

The SQL SELF JOIN is used to join a table to itself, If the table were two tables, temporarily renaming one table in the SQL statement.

 

18.What is cross join?

If we join two table without where cluase ,then tables join as cross products.

 

19.What is an ALIAS command?

ALIAS name assign to a table or column, we can use alias in where clause as refrence of table or columns.

 

20.What is the difference between TRUNCATE and DROP statements?

TRUNCATE delete the data,not the structure of table.
DROP command remove a table from the database and it cannot be rollback.

 

21.What is the difference between TRUNCATE and DROP statements?

TRUNCATE delete the data,not the structure of table.
DROP command remove a table from the database and it cannot be rollback.

 

22.What is the difference between TRUNCATE and delete statements?

TRUNCATE delete the data,not the structure of table, no commitand where clause required with truncate statement.
delete command remove a data from table, we can use where clause and commit with delete statement.

 

23.Operator is used in query for pattern matching ?

LIKE operator is used for pattern matching,
% – Matches zero or more characters.
_(Underscore) – Matching exactly one character.

 

24.How we can find EVEN NUMBER records from a table ?

select * from emp where rowid in (select decode(mod(rownum,2),0,rowid, null) from emp);

 

25.How we can find ODD NUMBER records from a table ?

select * from emp where rowid in (select decode(mod(rownum,2),0,null, rowid) from emp); p> 


Next