Sql Server Tricky Interview Questions

1. What is the output of select count(0) ?
Ans. 1

2. Quess output of the below query ?
DECLARE @ssn varchar(8) 
SET @ssn=123456789
SELECT @ssn as ssn

Ans. *

3. Write a query to combine student names from below table ?
StudentTable
StdID StdName
1        A
2        B
3        D

Ans. select StdName+',' from StudentTable for XML Path ('')

4. Write a query to find in how many objects StudentTable is referrred ?
Ans. 

SELECT *FROM SYS.SYSCOMMENTS SC 
INNER JOIN SYS.SYSOBJECTS SO ON SC.ID = SO.ID
AND SC.TEXT LIKE '%StudentTable%'

5. What is the output of below query ?
select 1
union 
select 1,2
Ans. Throws error. Must have equal number of columns in target list.

6. What is the output of below queries ?
1. select 1
    union 
    select '1'

2. select 1
    union all
    select '1'

Ans. 
First Query : Since union returns only distinct values
1
Second Query : Union all returns duplicates as well.
1
1

7. What is the output of below query ?
select null
union
select null
Ans. null

8. What is the outcome of below query ?

select 0 + count(0)
Ans. 1








Recent Posts

Categories
Subscribe

Receive Quality Tutorials Straight in your Inbox by submitting your Email below:

Delivered by FeedBurner

Protected by Copyscape Duplicate Content Checker