日期:2012-06-30 12:08:00 来源:本站整理
sql不常用函数总结以及事件,增添,删除触发器[MSSQL防范]
本文“sql不常用函数总结以及事件,增添,删除触发器[MSSQL防范]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
sql不常用函数总结以及事件,增添,删除触发器
distinct 删除反复行
declare @x 申明一个变量
convert(varchar(20),tscore.tenglish) 范例转换
cast(xx as varchar(10)) 范例转换
www.jb51.net
======================================================
情形
case
when xxx then xx
when xxxx then xxxxx
else
end
=======================================================
while xxx
begin
xxxxxx
end
www.jb51.net
事件
===================================================
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 www.jb51.net
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 www.jb51.net
=========================================
删除时触发器
create trigger tri_TblClass_delete_after
on TblClass instead of delete
as
begin
insert into TblClassBak
select * from deleted
end
========================================
作者 xhccom
以上是“sql不常用函数总结以及事件,增添,删除触发器[MSSQL防范]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
本文地址: | 与您的QQ/BBS好友分享! |
评论内容只代表网友观点,与本站立场无关!
评论摘要(共 0 条,得分 0 分,平均 0 分)
查看完整评论