PUZZLE1 – What is the output of the below query NEWID

Posted on : 30-06-2011 | By : Devi Prasad | In : Puzzles

0



What is the output of the following query:

DECLARE  @TEMPNEWID TABLE (iden int identity(1,1),COL1 int,COL2 UNIQUEIDENTIFIER)

INSERT INTO @TEMPNEWID(COL1,COL2)
SELECT 1,NEWID()
UNION
SELECT 2,NEWID()
UNION
SELECT 3,NEWID()
UNION
SELECT 4,NEWID()
UNION
SELECT 5,NEWID()
UNION
SELECT 6,NEWID()
UNION
SELECT 7,NEWID()
UNION
SELECT 8,NEWID()
UNION
SELECT 9,NEWID()
UNION
SELECT 10,NEWID()
UNION
SELECT 11,NEWID()
UNION
SELECT 12,NEWID()

DELETE T FROM 
@tempnewid AS T 
INNER JOIN (SELECT TOP 3 iden FROM 
             @tempnewid ORDER BY NEWID() ) as T1 
ON T.iden = T1.iden 

SELECT COUNT(*) FROM @tempnewid

How many records will be deleted from table variable @tempnewid?
What will be the output of count(*)?




Reference : Devi Prasad (sqlserverlearner.com)

Do you like my blog?

If you liked reading this blog, please help spread the word by sharing this blog with your friends.



Need Help On SQL Server?

Cannot Find Solution to your problem (or) If you are looking for some help on SQL Server. Dont worry Click Here to Post your question and solve your issue.




Your Ad Here