T-SQL DML学习笔记
1. select 语句的基本结构是
select -->From-->where àgroup By àHaving àOrder By
2. Exists 条件
Exists 后面括号内的条件语句如果为真的话 这此次查询继续 ,如Exists跟的条件语句没有查询到数据则前面语句块的查询不再执行下去
select provincename as '省名' from tb_province where Exists(select * from tb_province where tb_id=10)
3. into 语句
select * into tableName from tbName 其中tableName 则为临时表表明
4. insert语句
insert into TbName (字段一,字段二,字段三) select a.字段一,a.字段二,a.字段三 from TableName as a
5. Update 语句
Updata TbName
Set 字段=(select 字段同类型 from tbName )
6 Delete 与 Truncate 清空表
Delete from tbName 等效于 Truncate Tabel Customer
Delete 于 Truncate 区别: Truncate Table 不把删除的行放在事务日志中,因此不能撤销此语句。同时我们再使用Truncate Table语句也不能激活该表的delete触发器不能再外键约束中作为父表引用的表上使用Trancate Table 语句
.
7.
select case
when sex =0 then '女'
when sex =1 then '男'
Else ‘未知’
end
as myID
from tb_hntourline