How to restore a trigger in SQL Server?

I use the statement drop trigger if exist TRIGGERin sqlite, but the sql server does not like the if statement. (I assume that there is an insulting word). I am doing this right next to my creation of a trigger statement because I want to reset old triggers with the same name so that I can replace it with a new one.

How to do it on a SQL server?

+3
source share
4 answers

You can check for a specific trigger like this.

IF EXISTS
(
select name
from sys.objects
where type='TR' and name ='Trigger Name'
)
BEGIN

--Add your Trigger create code here

END
+2
source

SQL Server Management Studio (, , Query Analyzer) Script -as, "Drop Trigger" , SSMS T -SQL, .

, T-SQL, , , .

+4

, SQL Server, MySQL DROP TRIGGER IF EXISTS:

IF OBJECT_ID('XXXX', 'TR') IS NOT NULL
    DROP TRIGGER XXXX
+2

- :

IF objectproperty(object_id('dbo.xxx'), 'isTrigger') = 1
    DROP PROCEDURE dbo.xxx
GO
CREATE TRIGGER dbo.xxx [etc]

xxx ( dbo , ).

ALTER TRIGGER dbo.xxx [etc]
0

Source: https://habr.com/ru/post/1746192/


All Articles