sql不常用函数总结以及事务,增加,删除触发器
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
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
相关推荐
李轮清 2020-05-11
chenjiazhu 2019-12-17
ncomoon 2020-06-14
hanshangzhi 2020-06-12
daillo 2020-04-07
勇往直前 2020-02-02
韩学敏 2020-01-02
mengsun 2014-05-27
dreamhua 2019-12-26
talkingDB 2019-12-02
liuyang000 2019-11-09
小树不倒我不倒 2019-07-05
zjuwangleicn 2020-06-25
debugjoker 2020-06-17
昊 2020-06-16
sunnyxuebuhui 2020-06-14
hanshangzhi 2020-06-14
wudaokouer 2020-04-16
一昕之代码 2020-02-20