這篇文章將為大家詳細(xì)講解有關(guān)sql中怎么創(chuàng)建sqlserver數(shù)據(jù)庫(kù)觸發(fā)器,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個(gè)參考,希望大家閱讀完這篇文章后對(duì)相關(guān)知識(shí)有一定的了解。
在北鎮(zhèn)等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場(chǎng)前瞻性、產(chǎn)品創(chuàng)新能力,以專(zhuān)注、極致的服務(wù)理念,為客戶(hù)提供做網(wǎng)站、網(wǎng)站設(shè)計(jì) 網(wǎng)站設(shè)計(jì)制作按需求定制開(kāi)發(fā),公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),品牌網(wǎng)站設(shè)計(jì),全網(wǎng)整合營(yíng)銷(xiāo)推廣,外貿(mào)營(yíng)銷(xiāo)網(wǎng)站建設(shè),北鎮(zhèn)網(wǎng)站建設(shè)費(fèi)用合理。
代碼如下: --會(huì)員表 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 --會(huì)員等級(jí)表 if object_id('userlevel','u') is not null drop table userlevel go --插入測(cè)試數(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 --測(cè)試 update userinfo set user_tegral=100 where userid=1 select * from userinfo --另外一個(gè)觸發(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ù)庫(kù)觸發(fā)器就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到。