溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

sql中怎么創(chuàng)建sqlserver數(shù)據(jù)庫觸發(fā)器

發(fā)布時間:2021-08-04 16:15:07 來源:億速云 閱讀:152 作者:Leah 欄目:數(shù)據(jù)庫

這篇文章將為大家詳細(xì)講解有關(guān)sql中怎么創(chuàng)建sqlserver數(shù)據(jù)庫觸發(fā)器,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關(guān)知識有一定的了解。

代碼如下: --會員表 if object_id('userinfo','u') is not null drop table userinfo go create table userinfo(userid int primary key,user_tegral int,level int) insert into userinfo select 1,0,0 go --會員等級表 if object_id('userlevel','u') is not null drop table userlevel go --插入測試數(shù)據(jù) create table userlevel(level int primary key,mlevel_point decimal(10,2)) insert into userlevel select 0,0 insert into userlevel select 1,100 insert into userlevel select 2,200 insert into userlevel select 3,300 go --觸發(fā)器 create trigger TR_userInfor on userinfo for update as begin update a set a.level=b.level from userinfo a,userlevel b where a.userid in(Select userid from inserted) and a.user_tegral>=b.mlevel_point and a.user_tegral<(Select min(mlevel_point) from userlevel where mlevel_point>b.mlevel_point) end --測試 update userinfo set user_tegral=100 where userid=1 select * from userinfo --另外一個觸發(fā)器 set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go ALTER TRIGGER [AlterName] ON [dbo].[FS_User] FOR INSERT AS BEGIN SET NOCOUNT ON; UPDATE dbo.FS_User SET uname=(SELECT uname FROM Inserted)+'@ml' WHERE id IN (SELECT id FROM inserted) END

關(guān)于sql中怎么創(chuàng)建sqlserver數(shù)據(jù)庫觸發(fā)器就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI