sql不常用函数总结以及事务,增加,删除触发器
来源:asp之家 时间:2012-07-11 16:03:42
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
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python实现二叉树前序、中序、后序及层次遍历示例代码
python使用pynput库操作、监控你的鼠标和键盘
![](https://img.aspxhome.com/file/2023/3/124793_0s.png)
Golang 单元测试和基准测试实例详解
![](https://img.aspxhome.com/file/2023/8/128688_0s.jpg)
js实现带有介绍的Select列表菜单实例
![](https://img.aspxhome.com/file/2023/3/135823_0s.jpg)
Python Unittest ddt数据驱动的实现
Python数字/字符串补零操作实例代码
![](https://img.aspxhome.com/file/2023/4/80384_0s.png)
Python使用Pickle模块进行数据保存和读取的讲解
不能安装SQL Server 2005的问题及解决方法
Python 根据数据模板创建shapefile的实现
php引用地址改变变量值的问题
Go语言操作数据库及其常规操作的示例代码
python通过urllib2获取带有中文参数url内容的方法
python 利用pywifi模块实现连接网络破解wifi密码实时监控网络
nodejs高版本降为低版本的详细解决方案
![](https://img.aspxhome.com/file/2023/3/129473_0s.png)
vscode配置远程开发与免密登录的技巧
![](https://img.aspxhome.com/file/2023/3/132403_0s.png)
keras实现VGG16 CIFAR10数据集方式
![](https://img.aspxhome.com/file/2023/4/103664_0s.jpg)