Tags

, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,


SQL Server Interview Puzzles – III

Here I come with few interview questions asked to me or some of friends last few years. They were either asked to us in interview or via SQL tests. Test your skills and enjoy !


--

--SQL Server Quiz

--Q1.


CREATE TABLE #testOutputClause
(
	Id INT IDENTITY PRIMARY KEY
)
GO

INSERT INTO #testOutputClause DEFAULT VALUES
GO 3

SELECT @@ROWCOUNT

--Q2


CREATE TABLE #testNull 
(	
	Id INT
)
GO

INSERT INTO #testNull VALUES (7),(9),(-1),(NULL)

SELECT Id FROM #testNull WHERE Id <> 1

--Q3. 


DECLARE @V VARCHAR(MAX)
SET @V = REPLICATE('$',100000) 
SELECT LEN(@V)


--Q4. 


DECLARE @ NVARCHAR(MAX)
SET @ = REPLICATE('d',16000) 
SELECT LEN(@)


--Q5.


DECLARE @strValue VARCHAR
SELECT ISNULL(@strValue,'I am NULL')


--Q6.


DECLARE @strValue1 VARCHAR
SELECT COALESCE(@strValue1,'I am NULL')


--Q7.


CREATE TABLE #Nulls1 
(	
	Id INT
)
GO

INSERT INTO #Nulls1 VALUES (7),(9),(-1),(NULL)

SELECT COUNT(1) , COUNT(*) , SUM(1) , COUNT(Id) 
FROM #Nulls1


--Q8. 


DECLARE @V1 VARCHAR(MAX)
SET @V1 = REPLICATE('$',100000) 
SELECT DATALENGTH(@V1)


--Q9. 


DECLARE @1 NVARCHAR(MAX)
SET @1 = REPLICATE('d',16000) 
SELECT DATALENGTH(@1)


--Q10. 

CREATE TABLE #Nulls2
(	
	Id INT
)
GO

SELECT SUM(Id) , COUNT(1) FROM #Nulls2

--

Advertisements