2012.6.19.sql不常用函数总结,以及事务,增加,删除触发器

distinct 删除重复行

declare @x 申明一个变量

convert(varchar(20),tscore.tenglish) 类型转换

cast(xx as varchar(10)) 类型转换

======================================================

情况
case
   when  xxx  then xx
   when xxxx then xxxxx
   else
end

=======================================================

while xxx
begin
      xxxxxx
end


事务
===================================================
begin tran
declare @sum int = 0
update bank set balance=balance-1000 where cid='0001'
set @sum=@sum+@@error
update bank set balance=balance + 1000 where cid='0002'
set @sum=@sum+@@error

if @sum<>0
begin
 rollback
 print '回滚!'
end
else
begin
 --提交事务
 commit tran
 print '提交了!'
end
===================================================
begin tran
begin try
 declare @sum int = 0
 update bank set balance=balance-900 where cid='0001'
 set @sum=@sum+@@error
 update bank set balance=balance + 900 where cid='0002'
 set @sum=@sum+@@error
 commit
end try
begin catch
 rollback
end catch
=====================================================

declare @halfCount int= ceiling(@count/2.0) 向上

增加时触发器
=========================================
create trigger tri_TblClass_insert_after
on TblClass after insert
as
begin
declare @id int
declare @name varchar(50)
declare @desc varchar(50)
select @id=tclassId,@name=tclassname,@desc=tclassdesc from inserted

print @id
print @name
print @desc
end
=========================================

删除时触发器
create trigger tri_TblClass_delete_after
on TblClass instead of delete
as
begin
 
 insert into TblClassBak
 select * from deleted
end
========================================

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值