1. Back To Blog

Various interview questions on SQL Server

In this part we have tried to put some light on various SQL Server interview questions asked by the interviewer. So here we go with SQL Server questions.

 What is primary key in SQL?

 Primary key let us uniquely identify the row in a table.

 How it is different from Unique key?

 Primary key never accepts null value whereas in case of unique key one of the values can be null.

 Can you write down a query which will display the current financial year?

 

Declare@CurrentDatedate='2014/1/16'

Declare@FinancialYearvarchar(100)=''

if(month(@CurrentDate)>3)

begin

       selectDatePart(yy,@CurrentDate),DatePart(yy,DateAdd(yy,+1,@CurrentDate))

end

else

begin

       selectDatePart(yy,DateAdd(yy,-1,@CurrentDate)),DatePart(yy,@CurrentDate)

end

 

How will you find the index of a particular character in a SQL variable?

 

We will use CharIndex method.

 Let say we have multiple queries and we have to show result set of all queries as one result. What we have to do? 

Use Union. 

 Is it possible to use order by with UNION?

We cannot write order by in each query but can in last query which will affect entire result set.

For more SQL Server interview questions and .NET Interview Questions and Answers videos visit QuestPond.com

Get revised with most asked SQL Server Interview Questions with below 1 hour tutorial  :-

Shiv Prasad Koirala

Visit us @ www.questpond.com or call us at 022-66752917... read more

We are on Social