Trigger for deleting all member information

Source: Internet
Author: User

Previously, when the project administrator deletes member information in the background, all table information related to members should be deleted. Here, deletion refers to logical deletion, which changes the record status to the deleted state, rather than physical deletion from the database. Although the project manager does not require the trigger schemeProgramCheck whether the SQL Server trigger is implemented by setting the SQL server status.

TheCodeAs follows:

 
1:--- Delete the enterprise member with the specified membershipid in the membership member information table (in fact, no physical deletion is performed, but the status is set to-1)

2:--- Logically Delete the information in the information table related to enterprise members, that is, set status to-1.

3:If exists (select 1 from SYS. triggers where name ='Membership _ Update')

4:Drop trigger membership_update

 
5:Go

 
6:Create trigger membership_update

7:On Membership

8: ForUpdate

9: As

10:Begin

11:Declare @ membershipidAs Int, @ StatusAs Int

12:Select @ membershipid = membershipid, @ status = status from inserted;

13: If@ Status =-1

14:Begin

15:Update company set status = @ statusWhereMembershipid = @ membershipid;

16:Update supply set status = @ statusWhereMembershipid = @ membershipid;

17:Update buy set status = @ statusWhereMembershipid = @ membershipid;

18:Update companynews set status = @ statusWhereMembershipid = @ membershipid;

19:Update honor set status = @ statusWhereMembershipid = @ membershipid;

20:Update friendlink set status = @ statusWhereMembershipid = @ membershipid;

21:Update [Message] Set status = @ statusWhereMembershipid = @ membershipid;

22:Update employment set status = @ statusWhereMembershipid = @ membershipid;

23:Update Notice set status = @ statusWhereMembershipid = @ membershipid;

24:End

 
25:End

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.