Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to create sqlserver database trigger in sql

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article will explain in detail how to create sqlserver database triggers in sql. The content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

The code is as follows:-- membership table 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 go-- membership rating table if object_id (' userlevel','u') is not null drop table userlevel go-- insert test data create table userlevel (level int primary key) Insert into userlevel select 0 insert into userlevel select 1100 insert into userlevel select 2200 insert into userlevel select 3300 go-- trigger 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_tegralb.mlevel_point) end-- Test update userinfo set user_tegral=100 where userid=1 select * from userinfo-- another trigger 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

On how to create sqlserver database triggers in sql to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report