SQL Realtime Interview Questions
1. What is COALESCE in
SQL Server?
COALESCE
is used to return first non-null expression within the arguments. This function
is used to return a non-null from more than one column in the arguments.
Example – Select COALESCE(empno, empname, salary) from employee;
2.
Can we check locks in database? If so, how can we do this lock check?
Yes, we can check locks in the database. It can be
achieved by using in-built stored procedure called sp_lock.
3. What will be the maximum number of index per table?
1000 Index can be used as maximum number per table. 1 Clustered Index and 999 Non-clustered indexes per table can be used in SQL Server.
4. How data can be copied from one table to another table?
INSERT INTO SELECT
This command is used to insert data into a table which is already created.
SELECT INTO
This command is used to create a new table and its structure and data can be copied from existing table.
5. What is Query to
find Second highest salary for employee?
This is most asked Real
Time Scenarios in SQL in many industries. User can try multiple queries to find
out the same result.
Query 1 :
Select distinct Salary from Employee e1 where 2= select count(distinct salary) from Employee e2 where e1.salary<=e2.salary
Query 2:
select min(salary) from (select distinct salary from emp order by
salary desc) where rownum<=2
Query 3:
select * from(Select S.*,DENSE_RANK() OVER (PARTITION BY DNO ORDER
BY SALARY DESC) DR from Source) S Where S.DR=2;
Author: Jilpa Gambhir
Comments
Post a Comment