Adding a trigger to SQL server does not allow data deletion

Source: Internet
Author: User
The SQL Server add trigger does not allow data deletion. The trigger is of the insteadofdelete type. Note: The trigger of the instead type is equivalent to directly following the code in the trigger after the DELETE command is run. If there is no such trigger, this trigger will block all your DELETED commands. Instead, only the code in the trigger will be executed. If

The SQL Server add trigger does not allow data deletion. The trigger of the instead type is of the instead type. Note: The trigger of the instead type directly follows the code in the trigger after the delete command is run, if no, this trigger will block all your DELETED commands. Instead, only the code in the trigger will be executed. If

Adding a trigger to SQL server does not allow data deletion

The trigger is: instead of delete type, website space. Note: The trigger of instead type is equivalent:
After the DELETE command is run, the U.S. server directly goes through the code in the trigger and goes down. No more ......
That is to say, this trigger will block all your DELETED commands. Instead, only the code in the trigger will be executed.

If you comment out the code in this trigger, the server space is equivalent to blocking all DELETE commands.

Create trigger [dbo]. [trg_del] on [dbo]. [drv_user]
Instead of delete
AS
BEGIN
Declare @ cou int
Select @ cou = count (*) from deleted;
If (@ cou> 0)
RAISERROR ('data cannot be deleted! ', 16, 1)
END

Posted on

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.