程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> 其他數據庫知識 >> 更多數據庫知識 >> sql不常用函數總結以及事務,增加,刪除觸發器

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

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved