×

Loading...
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。

TSQL knowledge test. for fun only.

do not test it on your database, just think about it.
suppose you run the following tsql on sqlserver or sybase:

create table dropit (col1 varchar(9),col2 varchar(9))
select * from dropit
drop table dropit
create table aa (col1 varchar(9),col3 varchar(9))
insert into dropit values ('1','1')
insert aa values ('1','a')
insert aa values ('1','aa')
select * from aa
update dropit set col2=a.col3 from dropit d,aa a where d.col1=a.col1
select col2 from dropit

what the result you expect for dropit.col2? a or aa
Report

Replies, comments and Discussions:

  • 工作学习 / IT技术讨论 / TSQL knowledge test. for fun only.
    • create table dropit (col1 varchar(9),col2 varchar(9)) select * from dropit drop table dropit create table aa (col1 varchar(9),col3 varchar(9)) insert into dropit values ('1','1') -- the table does not exist
      • sorry, comment out "drop table dropit". this actually is testing you update one row with 2 return value. in Oracle the same logic will give you error immediately, but tsql not, the result is unpredictable.
        create table dropit (col1 varchar(9),col2 varchar(9))
        --select * from dropit
        --drop table dropit
        create table aa (col1 varchar(9),col3 varchar(9))
        insert into dropit values ('1','1')
        insert aa values ('1','a')
        insert aa values ('1','aa')
        --select * from aa
        update dropit set col2=a.col3 from dropit d,aa a where d.col1=a.col1
        select col2 from dropit