SQL Interview Questions/HCL interview questions/Freshers/Experience/Tricky Interview Questions

 1.WHAT IS THE OUTPUT OF THE FOLLOWING CODE.

declare @i int=1

;with cte as

(

select @i as id 

union all 

select id+2 from cte 

where id<=5

)

select * from cte

OUTPUT:-

1

3

5

7


2)WHAT IS THE OUTPUT OF THE FOLLOWING CODE.

declare @i int=1

declare @j int=1

print @i

print @j

while @i<3

begin

  set @i=@j+1

  set @j=@i

  print @i

  print @j

end

OUTPUT:-

1

1

2

2

3

3


3.WHAT IS THE OUTPUT OF THE FOLLOWING CODE.

create table source_table

(id int,

name varchar(100)

)

insert into source_table values (1,'A') , (1,'B') ,(2,'C') ,(3,'D')

 select * from source_table                  


 CREATE TABLE target_table

 (

id  INT,

name VARCHAR(10)

)

 INSERT INTO target_table VALUES (1,'X'),(2,'Y')

 select * from target_table

                                     


MERGE target_table AS T using source_table AS S ON T.id=S.id

WHEN MATCHED THEN UPDATE SET `T.name=S.name;

 

OUTPUT:-

This code gets ERROR because  source table having duplicate values  in the id column .

Need to remember if source table has duplicate values, merge statement will not execute.






Comments

Popular posts from this blog

SQL Interview Questions:3

AZURE DATA FACTORY INTERVIEW QUESTIONS: FILES FORMATS

AZURE DATA FACTORY INTERVIEW QUESTIONS :ACTIVITIES AND TYPES.