[],#,重复数据删除、表别名
1.[]
数据库中[]是为了区分关键字跟其他字符的作用
2.#
临时表
Create table #tmp
(
ID varchar(50)
,Name varchar(50))
或同 select * into #tab from User
3. 重复数据的查看删除
http://www.cnblogs.com/sunxiaonan/archive/2009/11/24/1609439.html
4.表别名 & 数据更新update
use master select * from dbo.SY_AdManage t where t.ID>4
同 use master select * from dbo.SY_AdManage as t where t.ID>4
update CCP_Org
set CCP_Org.OrgEmail=(select BelongToUnit from CCP_Org b where b.OrgCode= CCP_Org.OrgCode)
where CCP_Org.OrgCode in
(
'001.001.050.005.028',
'001.001.050.030.027.219'
)
update TableA
set TableA.NextKey = T.Key
from
(
select * from TableA
)T
where T.Index = TableA.Index + 1
使用别名可以得到更简洁的写法:
update T1
set T1.NextKey = T2.Key
from TableA T1, TableA T2
whereT2.Index = T1.Index + 1