当前位置: 代码迷 >> Sql Server >> 奇怪: delete from 不能用表别名吗?该怎么解决
  详细解决方案

奇怪: delete from 不能用表别名吗?该怎么解决

热度:390   发布时间:2016-04-27 13:24:43.0
奇怪: delete from 不能用表别名吗?
如题,sql server 2000

delete from #ta where exists (select 1 from #tb b where #ta.id=b.id) 

上面是可以的,但是如果用了#ta的别名,就不行了,提示 : 'a'附近有语法错误 

delete from #ta a where exists (select 1 from #tb b where a.id=b.id)

------解决方案--------------------
SQL code
delete afrom #ta a where exists (select 1 from #tb b where a.id=b.id)
------解决方案--------------------
delete #ta from #ta a where exists (select 1 from #tb where id=a.id)
------解决方案--------------------
学习一下
------解决方案--------------------
终于明白为什么了,原来DEL语句真正删除的是delete语句后的那张表不信建张#tc表打上

delete #tc from 后的语句随便打只要符合语法规则出不出现#tc无所谓看看究竟被删除的是那张表
------解决方案--------------------
SQL code
delete a--用别名 from #ta a where exists (select 1 from #tb b where a.id=b.id) delete #ta --用别名 from #ta a where exists (select 1 from #tb b where a.id=b.id) -------以上两种都可以
------解决方案--------------------
学习
  相关解决方案