SQL Server Interview Questions of Videos
SQL Server Interview Questions of Videos
www.questpond.com
Contents
Question 1 :- Explain normalization ? ................................................................................................. 3
Question 2 :- How to implement normalization ? .............................................................................. 3
Question 3 :- What is denormalization ? ............................................................................................ 3
Question 4 :- Explain OLTP vs OLAP ? ................................................................................................. 3
Question 5 :- Explain 1st,2nd and 3rd Normal form ? ........................................................................ 3
Question 6 :- Primary Key vs Unique key ? ........................................................................................ 3
Question 7 :- Differentiate between Char vs Varchar ? ..................................................................... 3
Question 8 :- Differentiate between Char vs NChar ? ....................................................................... 4
Question 9 :- Whats the size of Char vs NChar ? ............................................................................... 4
Question 10 :- What is the use of Index ? ........................................................................................... 4
Question 11 :- How does it make search faster? ............................................................................... 4
Question 13 :- Clustered vs Non-Clustered index .............................................................................. 4
Question 14 :- Function vs Stored Procedures .................................................................................. 4
Question 15 :- What are triggers and why do you need it ? .............................................................. 5
Question 16 :- What are types of triggers ? ....................................................................................... 5
Question 17 :- Differentiate between After trigger vs Instead Of ? .................................................. 5
Question 18 :- What is need of Identity ? ........................................................................................... 5
Question 19 :- Explain transactions and how to implement it ? ........................................................ 5
Question 20 :- What are inner joins ? ................................................................................................. 5
Question 21 :- Explain Left join ? ........................................................................................................ 5
Question 22 :- Explain Right join ? ...................................................................................................... 5
Question 23 :- Explain Full outer joins ? ............................................................................................. 5
Question 24 :- Explain Cross joins ? .................................................................................................... 6
Question 25:-Why do we need UNION ? ............................................................................................ 6
Question 26:-Differentiate between Union vs Union All ? ................................................................. 6
Question 27:-can we have unequal columns in Union? ..................................................................... 7
Question 28:-Can column have different data types in Union ? ........................................................ 7
Question 29:- Which Aggregate function have you used ? ................................................................ 8
Question 30:- When to use Group by ? .............................................................................................. 9
Question 31:- Can we select column which is not part of group by ? ................................................ 9
Question 32:- What is having clause ? ................................................................................................ 9
Question 33:- Having clause vs Where clause .................................................................................. 10
Question 34:- How can we sort records ? ......................................................................................... 10
Question 35:- What’s the default sort ? ........................................................................................... 10
Question 36:- How can we remove duplicates ? .............................................................................. 10
Question 37:- Select the first top X records ? ................................................................................... 11
Question 38:- How to handle NULLS ? .............................................................................................. 11
Question 39:- What is use of wild cards ?......................................................................................... 11
Question 40:- What is the use of Alias ? ........................................................................................... 11
Question 41:- How to write a case statement ? ............................................................................... 12
Question 42:- What is self reference tables ? ................................................................................... 12
Question 43:- What is self join ? ....................................................................................................... 12
Question 44:- Explain the between clause ?..................................................................................... 13
Question 45:-Explain SubQuery ? ..................................................................................................... 14
Question 46:-Can inner Subquery return multiple results ?............................................................. 14
Question 47:-What is Co-related Query ?......................................................................................... 14
Question 48:-Differentiate between Joins and SubQuery ? ............................................................. 14
Question 49: -Performance Joins vs Subquery? ............................................................................... 14
Question 50:- Select the top nth highest salary using top and order by? ....................................... 14
Question 51:- Select the top nth highest salary using correlated Queries? ..................................... 14
Question 52:- Select top nth using using TSQL ................................................................................ 15
Question 53:- Performance comparison of all the methods. .......................................................... 15
Question 1 :- Explain normalization ?
→ Normalization is a database design technique to remove redundant data.
2nd Normal form :- First normal form should be satisfied. All non-key columns should be fully
dependent on the Primary key.
3rd Normal :- All 1st and 2nd normal form should be satisfied. No transient dependency should be
present.
1st N NULLS :- Unique can have NULLS , but primary key can not have NULLS.
2nd N Numbers :- Many unique keys but ony ONE Primary key.
But will not make any permanent changes to the Can change the environment.
environment.
Insert, Updates and Deletes
Only Selects allowed, insert/update/deletes not allowed.
allowed.
Execution Can be called from select/where/call from other Stored procedures can not be
Stored procedure. executed from Select/Where or
from other functions.
Output Mostly Scalar value, Table valued functions. Can have single or multiple
outputs.
Function returns Computed Scalar values. You cannot make permanent changes (insert, update,
delete) inside function.
Stored procedure is a mini-programs which can do anything , make changes , backup database.
→ Union combines result sets and excludes duplicates while Union all also combines result set but
includes duplicates.
select [ProductId],
[ProductName]
from [LearnSql].[dbo].[mst_Products]
union all
select [ProductId],
[ProductName]
from [LearnSql].[dbo].[mst_ExpiredProducts]
Question 27:-can we have unequal columns in Union?
→ No.
select
[ProductName]
from [LearnSql].[dbo].[mst_Products]
union all
select [ProductId],
[ProductName]
from [LearnSql].[dbo].[mst_ExpiredProducts]
select
[ProductName],
[ProductId]
from [LearnSql].[dbo].[mst_Products]
union all
select
[ProductId],
[ProductName]
from [LearnSql].[dbo].[mst_ExpiredProducts]
select sum([CustomerAmount]),
Avg([CustomerAmount]) ,
min([CustomerAmount]),
max([CustomerAmount]),
Count(*)
from [dbo].[txn_Customer]
Question 30:- When to use Group by ?
select [ProductName],sum([CustomerAmount])
from [dbo].[txn_Customer]
group by [ProductName]
→No. In a group by you can only select columns which are present in groupby.
group by [ProductName]
group by [ProductName]
having [ProductName]='shoes'
Having Where
select [CustomerName],
case
else 'NA'
select t1.Id,t1.Referenceid_fk,
from txn_Customer as t1
inner join
txn_Customer t2 on t1.id=t2.Referenceid_fk
Subquery Join
Intention Series of processing where one Join two tables and get
processing sends output to matching or not matching
other. records.
Select fields Can not select from inner Can select multiple fields from
Query table.
→ Most of the times Joins should perform better. But not necessarily, its possible subquery can be
faster many times. So SQL plan needs to be looked in to determine whose performance can be
better.
Question 50:- Select the top nth highest salary using top and order by?
Select Top 1 EmployeeSalary from (select distinct Top 2 EmployeeSalary from tblEmployee order by
EmployeeSalary desc) as innerquery order by EmployeeSalary asc
Question 51:- Select the top nth highest salary using correlated Queries?
Note: Offset 1 rows means skip first row. So if we have to select the 2nd highest then offset skip 1st
row and then fetch 1st row from the remaining rows which is the second highest.