<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Triggers - MSSQL Query</title>
	<atom:link href="https://mssqlquery.com/category/triggers/feed" rel="self" type="application/rss+xml" />
	<link>https://mssqlquery.com</link>
	<description>MSSQL and TSQL Programming and TSQL Examples</description>
	<lastBuildDate>Fri, 07 Apr 2023 19:27:35 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.3.1</generator>

<image>
	<url>https://mssqlquery.com/wp-content/uploads/2023/06/cropped-mssql-query-icon-32x32.png</url>
	<title>Triggers - MSSQL Query</title>
	<link>https://mssqlquery.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Where is Trigger Used Most in SQL Server?</title>
		<link>https://mssqlquery.com/where-is-trigger-used-most-in-sql-server</link>
		
		<dc:creator><![CDATA[Yavuz Selim Kart]]></dc:creator>
		<pubDate>Sat, 11 Mar 2023 12:16:53 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Triggers]]></category>
		<category><![CDATA[SQL Server Trigger]]></category>
		<category><![CDATA[Trigger]]></category>
		<category><![CDATA[Trigger all database]]></category>
		<guid isPermaLink="false">https://mssqlquery.com/?p=1417</guid>

					<description><![CDATA[<p>Hello everyone, In this article, I will try to give information about where Triggers are used most in SQL Server. Triggers are used in SQL Server to automatically execute a set of SQL statements or stored procedures when specific database events occur, such as INSERT, UPDATE, or DELETE operations on&#46;&#46;&#46;</p>
<p>The post <a href="https://mssqlquery.com/where-is-trigger-used-most-in-sql-server">Where is Trigger Used Most in SQL Server?</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Hello everyone,</p>
<p>In this article, I will try to give information about where Triggers are used most in SQL Server.</p>
<p>Triggers are used in SQL Server to automatically execute a set of SQL statements or stored procedures when specific database events occur, such as INSERT, UPDATE, or DELETE operations on a table. Triggers are commonly used for the following purposes:</p>
<ol>
<li><strong>Enforcing Business Rules:</strong> Triggers can be used to enforce business rules and data integrity constraints. For example, a trigger can be used to prevent users from deleting a record if it is referenced by other records in the database.</li>
<li><strong>Auditing Changes:</strong> Triggers can be used to log changes made to database tables. For example, a trigger can be used to write a record to an audit trail table whenever a row is updated or deleted.</li>
<li><strong>Replicating Data:</strong> Triggers can be used to replicate data from one database to another. For example, a trigger can be used to replicate new records inserted into a table in one database to a table in another database.</li>
<li><strong>Updating Views:</strong> Triggers can be used to update views when underlying data is changed. For example, a trigger can be used to update a view that shows a list of employees whenever a new employee is added to the Employees table.</li>
<li><strong>Notification:</strong> Triggers can be used to send notifications to users or applications when specific events occur in the database. For example, a trigger can be used to send an email to a supervisor whenever a new employee is added to the Employees table.</li>
</ol>
<p>In summary, triggers are used in SQL Server for a variety of purposes, including enforcing business rules, auditing changes, replicating data, updating views, and sending notifications.</p>
<p>Good luck to everyone in business and life.</p>
<div class='epvc-post-count'><span class='epvc-eye'></span>  <span class="epvc-count"> 54</span><span class='epvc-label'> Views</span></div><p>The post <a href="https://mssqlquery.com/where-is-trigger-used-most-in-sql-server">Where is Trigger Used Most in SQL Server?</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Viewing Trigger Creation and Update Detail in SQL Server</title>
		<link>https://mssqlquery.com/viewing-trigger-creation-and-update-detail-in-sql-server</link>
		
		<dc:creator><![CDATA[Yavuz Selim Kart]]></dc:creator>
		<pubDate>Sun, 24 Jul 2022 10:55:44 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Triggers]]></category>
		<category><![CDATA[SQL Server Trigger]]></category>
		<category><![CDATA[Trigger Creation and Update Detail in SQL Server]]></category>
		<category><![CDATA[Viewing Trigger]]></category>
		<guid isPermaLink="false">https://mssqlquery.com/?p=1022</guid>

					<description><![CDATA[<p>Hello everyone, In this article, I will try to give information about the creation and updating of Trigger in SQL Server. In SQL Server, in some cases, you may want to view the creation and update details of the Trigger. You can easily do this using the code below. SELECT&#46;&#46;&#46;</p>
<p>The post <a href="https://mssqlquery.com/viewing-trigger-creation-and-update-detail-in-sql-server">Viewing Trigger Creation and Update Detail in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Hello everyone,</p>
<p>In this article, I will try to give information about the creation and updating of Trigger in SQL Server.</p>
<p>In SQL Server, in some cases, you may want to view the creation and update details of the Trigger.</p>
<p>You can easily do this using the code below.</p>
<pre class="line-numbers"><code class="language-sql">SELECT o.name AS [Trigger Name],
       CASE
           WHEN o.type = 'TR' THEN
               'SQL DML Trigger'
           WHEN o.type = 'TA' THEN
               'DML Assembly Trigger'
       END AS [Trigger Type],
       sc.name AS [Schema_Name],
       OBJECT_NAME(parent_object_id) AS [Table Name],
       o.create_date [Trigger Create Date],
       o.modify_date [Trigger Modified Date]
FROM sys.objects o
    INNER JOIN sys.schemas sc
        ON o.schema_id = sc.schema_id
WHERE (
          type = 'TR'
          OR type = 'TA'
      );</code></pre>
<p>When you run the above code, you will see a result similar to the one below.</p>
<p><img decoding="async" fetchpriority="high" class="alignnone wp-image-1025 size-full" src="https://mssqlquery.com/wp-content/uploads/2022/07/viewing-trigger-creation-and-update-detail-in-sql-server-1.jpg" alt="Viewing Trigger Creation and Update Detail in SQL Server" width="700" height="523" srcset="https://mssqlquery.com/wp-content/uploads/2022/07/viewing-trigger-creation-and-update-detail-in-sql-server-1.jpg 700w, https://mssqlquery.com/wp-content/uploads/2022/07/viewing-trigger-creation-and-update-detail-in-sql-server-1-300x224.jpg 300w" sizes="(max-width: 700px) 100vw, 700px" /></p>
<p>As you can see, we have displayed the creation and updating details of the Trigger.</p>
<p>Good luck to everyone in business and life.</p>
<div class='epvc-post-count'><span class='epvc-eye'></span>  <span class="epvc-count"> 206</span><span class='epvc-label'> Views</span></div><p>The post <a href="https://mssqlquery.com/viewing-trigger-creation-and-update-detail-in-sql-server">Viewing Trigger Creation and Update Detail in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Re-Enable All Triggers in SQL Server</title>
		<link>https://mssqlquery.com/re-enable-all-triggers-in-sql-server</link>
		
		<dc:creator><![CDATA[Yavuz Selim Kart]]></dc:creator>
		<pubDate>Fri, 08 Apr 2022 19:26:11 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Triggers]]></category>
		<category><![CDATA[Re-Enable All Triggers]]></category>
		<category><![CDATA[SQL Re-Enable All Triggers]]></category>
		<category><![CDATA[TSQL Enable Triggers]]></category>
		<guid isPermaLink="false">https://mssqlquery.com/?p=846</guid>

					<description><![CDATA[<p>Hello to everyone, In this article, I will try to give information about how to reactivate all Triggers in SQL Server. In SQL Server you may want to re-enable all Triggers in some cases. You can easily do this using the code below. EXEC sp_MSforeachtable 'ALTER TABLE ? ENABLE TRIGGER&#46;&#46;&#46;</p>
<p>The post <a href="https://mssqlquery.com/re-enable-all-triggers-in-sql-server">Re-Enable All Triggers in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Hello to everyone,</p>
<p>In this article, I will try to give information about how to reactivate all Triggers in SQL Server.</p>
<p>In SQL Server you may want to re-enable all Triggers in some cases.</p>
<p>You can easily do this using the code below.</p>
<pre class="line-numbers"><code class="language-sql">EXEC sp_MSforeachtable 'ALTER TABLE ? ENABLE TRIGGER ALL';</code></pre>
<p>You can re-enable all triggers by running this code.</p>
<p>Good luck to everyone in business and life.</p>
<div class='epvc-post-count'><span class='epvc-eye'></span>  <span class="epvc-count"> 154</span><span class='epvc-label'> Views</span></div><p>The post <a href="https://mssqlquery.com/re-enable-all-triggers-in-sql-server">Re-Enable All Triggers in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Trigger Preventing Table Creation in SQL Server</title>
		<link>https://mssqlquery.com/trigger-preventing-table-creation-in-sql-server</link>
		
		<dc:creator><![CDATA[Yavuz Selim Kart]]></dc:creator>
		<pubDate>Thu, 03 Mar 2022 17:17:16 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Triggers]]></category>
		<category><![CDATA[SQL Server Table Trigger]]></category>
		<category><![CDATA[SQL Server Trigger]]></category>
		<category><![CDATA[Trigger Table]]></category>
		<category><![CDATA[TSQL Trigger Example]]></category>
		<guid isPermaLink="false">https://mssqlquery.com/?p=754</guid>

					<description><![CDATA[<p>Hello everyone, In this article, I will provide information about creating triggers that prevent table creation in SQL Server. In SQL Server, in some cases, we may not want a table to be created in the current database. You can easily do this using the code below. CREATE TRIGGER StopTableCreation&#46;&#46;&#46;</p>
<p>The post <a href="https://mssqlquery.com/trigger-preventing-table-creation-in-sql-server">Trigger Preventing Table Creation in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Hello everyone,</p>
<p>In this article, I will provide information about creating triggers that prevent table creation in SQL Server.</p>
<p>In SQL Server, in some cases, we may not want a table to be created in the current database.</p>
<p>You can easily do this using the code below.</p>
<pre class="line-numbers"><code class="language-sql">CREATE TRIGGER StopTableCreation
ON DATABASE
FOR CREATE_TABLE
AS
PRINT 'This database does not allow new tables.';
ROLLBACK TRANSACTION;

--Create Table Code

CREATE TABLE Table1
(
    ID INT
);

</code></pre>
<p>When you run the above code, you will see a result similar to the one below.</p>
<p><img decoding="async" class="alignnone wp-image-757 size-full" src="https://mssqlquery.com/wp-content/uploads/2022/03/trigger-preventing-table-creation-in-sql-server-1.jpg" alt="Trigger Preventing Table Creation in SQL Server" width="700" height="96" srcset="https://mssqlquery.com/wp-content/uploads/2022/03/trigger-preventing-table-creation-in-sql-server-1.jpg 700w, https://mssqlquery.com/wp-content/uploads/2022/03/trigger-preventing-table-creation-in-sql-server-1-300x41.jpg 300w" sizes="(max-width: 700px) 100vw, 700px" /></p>
<p>As you can see, we could not create a table.</p>
<p>Good luck to everyone in business and life.</p>
<div class='epvc-post-count'><span class='epvc-eye'></span>  <span class="epvc-count"> 145</span><span class='epvc-label'> Views</span></div><p>The post <a href="https://mssqlquery.com/trigger-preventing-table-creation-in-sql-server">Trigger Preventing Table Creation in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Getting List of Disabled or Enabled Triggers in Database in SQL Server</title>
		<link>https://mssqlquery.com/getting-list-of-disabled-or-enabled-triggers-in-database-in-sql-server</link>
		
		<dc:creator><![CDATA[Yavuz Selim Kart]]></dc:creator>
		<pubDate>Tue, 01 Mar 2022 18:38:54 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Triggers]]></category>
		<category><![CDATA[Disabled or Enabled Triggers]]></category>
		<category><![CDATA[SQL Server Triggers]]></category>
		<category><![CDATA[Triggers in Database in SQL Server]]></category>
		<guid isPermaLink="false">https://mssqlquery.com/?p=750</guid>

					<description><![CDATA[<p>Hello everyone, In this article, I will provide information about getting the list of disabled or active Triggers in the database in SQL Server. In SQL Server, in some cases you may want to get the list of disabled or active Triggers. You can easily do this using the code&#46;&#46;&#46;</p>
<p>The post <a href="https://mssqlquery.com/getting-list-of-disabled-or-enabled-triggers-in-database-in-sql-server">Getting List of Disabled or Enabled Triggers in Database in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Hello everyone,</p>
<p>In this article, I will provide information about getting the list of disabled or active Triggers in the database in SQL Server.</p>
<p>In SQL Server, in some cases you may want to get the list of disabled or active Triggers.</p>
<p>You can easily do this using the code below.</p>
<pre class="line-numbers"><code class="language-sql">SELECT TBL.name AS TableName,
       SCHEMA_NAME(TBL.schema_id) AS Table_SchemaName,
       TRG.name AS TriggerName,
       TRG.parent_class_desc,
       CASE
           WHEN TRG.is_disabled = 0 THEN
               'Enable'
           ELSE
               'Disable'
       END AS TRG_Status
FROM sys.triggers TRG
    INNER JOIN sys.tables TBL
        ON TBL.object_id = TRG.parent_id
           AND TRG.is_disabled = 1; --use this filter to get Disabled/Enabled Triggers</code></pre>
<p>Good luck to everyone in business and life.</p>
<div class='epvc-post-count'><span class='epvc-eye'></span>  <span class="epvc-count"> 149</span><span class='epvc-label'> Views</span></div><p>The post <a href="https://mssqlquery.com/getting-list-of-disabled-or-enabled-triggers-in-database-in-sql-server">Getting List of Disabled or Enabled Triggers in Database in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Listing Active Triggers in SQL Server</title>
		<link>https://mssqlquery.com/listing-active-triggers-in-sql-server</link>
		
		<dc:creator><![CDATA[Yavuz Selim Kart]]></dc:creator>
		<pubDate>Thu, 24 Feb 2022 20:20:52 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Triggers]]></category>
		<category><![CDATA[Active Triggers in SQL Server]]></category>
		<category><![CDATA[All Trigger List in SQL Server]]></category>
		<category><![CDATA[SQL Server Triggers]]></category>
		<guid isPermaLink="false">https://mssqlquery.com/?p=695</guid>

					<description><![CDATA[<p>Hello everyone, In this section, I will talk about how to list active triggers in SQL Server. In SQL Server, in some cases, it may be necessary to list active triggers for the database. Using the code below, you can list your active triggers for your database. SELECT TAB.name AS&#46;&#46;&#46;</p>
<p>The post <a href="https://mssqlquery.com/listing-active-triggers-in-sql-server">Listing Active Triggers in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Hello everyone,</p>
<p>In this section, I will talk about how to list active triggers in SQL Server.</p>
<p>In SQL Server, in some cases, it may be necessary to list active triggers for the database.</p>
<p>Using the code below, you can list your active triggers for your database.</p>
<pre class="line-numbers"><code class="language-sql">SELECT TAB.name AS TabloAdi,
       TRIG.name AS TriggerAdi,
       TRIG.is_disabled AS Pasiflik
FROM [sys].[triggers] AS TRIG
    INNER JOIN sys.tables AS TAB
        ON TRIG.parent_id = TAB.object_id;</code></pre>
<p>When you run the query, you will see a result like the one below.</p>
<p><img decoding="async" class="alignnone wp-image-697 size-full" src="https://mssqlquery.com/wp-content/uploads/2022/02/listing-active-triggers-in-sql-server-1.jpg" alt="Listing Active Triggers in SQL Server" width="700" height="414" srcset="https://mssqlquery.com/wp-content/uploads/2022/02/listing-active-triggers-in-sql-server-1.jpg 700w, https://mssqlquery.com/wp-content/uploads/2022/02/listing-active-triggers-in-sql-server-1-300x177.jpg 300w" sizes="(max-width: 700px) 100vw, 700px" /></p>
<p>As you can see, all active triggers are listed.</p>
<p>Good luck to everyone in business and life.</p>
<div class='epvc-post-count'><span class='epvc-eye'></span>  <span class="epvc-count"> 241</span><span class='epvc-label'> Views</span></div><p>The post <a href="https://mssqlquery.com/listing-active-triggers-in-sql-server">Listing Active Triggers in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Procedure to Show Script of All Triggers in SQL Server</title>
		<link>https://mssqlquery.com/procedure-to-show-script-of-all-triggers-in-sql-server</link>
		
		<dc:creator><![CDATA[Yavuz Selim Kart]]></dc:creator>
		<pubDate>Tue, 02 Nov 2021 18:14:47 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Triggers]]></category>
		<category><![CDATA[Show Script of All Triggers in SQL Server]]></category>
		<category><![CDATA[SQL Server All Triggers List]]></category>
		<category><![CDATA[SQL Trigger Script List]]></category>
		<guid isPermaLink="false">https://mssqlquery.com/?p=274</guid>

					<description><![CDATA[<p>Hello to everyone, In this article, I will give information about the procedure that show the script of all triggers in SQL Server. In some cases, you may want to script all triggers in SQL Server. You can do this easily with the help of the procedure below. --Creating the&#46;&#46;&#46;</p>
<p>The post <a href="https://mssqlquery.com/procedure-to-show-script-of-all-triggers-in-sql-server">Procedure to Show Script of All Triggers in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Hello to everyone,</p>
<p>In this article, I will give information about the procedure that show the script of all triggers in SQL Server.</p>
<p>In some cases, you may want to script all triggers in SQL Server.</p>
<p>You can do this easily with the help of the procedure below.</p>
<pre class="line-numbers"><code class="language-sql">--Creating the Procedure

CREATE PROCEDURE [dbo].[SYS_ScriptAllTriggers]
    @ScriptMode int = 0
AS 
BEGIN

    DECLARE @script TABLE (script varchar(max), id int identity (1,1))

    DECLARE 
        @SQL VARCHAR(8000), 
        @Text            NVARCHAR(4000), 
        @BlankSpaceAdded INT, 
        @BasePos         INT, 
        @CurrentPos      INT, 
        @TextLength      INT, 
        @LineId          INT, 
        @MaxID           INT, 
        @AddOnLen        INT, 
        @LFCR            INT, 
        @DefinedLength   INT, 
        @SyscomText      NVARCHAR(4000), 
        @Line            NVARCHAR(1000), 
        @UserName        SYSNAME, 
        @ObjID           INT, 
        @OldTrigID       INT; 

    SET NOCOUNT ON; 
    SET @DefinedLength = 1000; 
    SET @BlankSpaceAdded = 0; 

    SET @ScriptMode = ISNULL(@ScriptMode, 0);

    -- This Part Validated the Input parameters   
    DECLARE @Triggers TABLE (username SYSNAME NOT NULL, trigname SYSNAME NOT NULL, objid INT NOT NULL); 
    DECLARE @TrigText TABLE (objid INT NOT NULL, lineid INT NOT NULL, linetext NVARCHAR(1000) NULL); 

    INSERT INTO 
        @Triggers (username, trigname, objid) 
    SELECT DISTINCT 
        OBJECT_SCHEMA_NAME(B.id), B.name, B.id
    FROM 
        dbo.sysobjects B, dbo.syscomments C 
    WHERE 
        B.type = 'TR' AND B.id = C.id AND C.encrypted = 0; 

    IF EXISTS(SELECT C.* FROM syscomments C, sysobjects O WHERE O.id = C.id AND O.type = 'TR' AND C.encrypted = 1) 
    BEGIN 

        insert into @script select '/*'; 
        insert into @script select 'The following encrypted triggers were found'; 
        insert into @script select 'The procedure could not write the script for it'; 

        insert into 
            @script 
        SELECT DISTINCT 
            '[' + OBJECT_SCHEMA_NAME(B.id) + '].[' + B.name + ']' --, B.id 
        FROM   
            dbo.sysobjects B, dbo.syscomments C 
        WHERE  
            B.type = 'TR' AND B.id = C.id AND C.encrypted = 1; 

        insert into @script select '*/'; 
    END; 

    DECLARE ms_crs_syscom CURSOR LOCAL forward_only FOR 
    SELECT 
        T.objid, C.text
    FROM   
        @Triggers T, dbo.syscomments C 
    WHERE  
        T.objid = C.id 
    ORDER  BY T.objid, 
        C.colid 
    FOR READ ONLY; 

    SELECT @LFCR = 2; 
    SELECT @LineId = 1; 

    OPEN ms_crs_syscom; 

    SET @OldTrigID = -1; 

    FETCH NEXT FROM ms_crs_syscom INTO @ObjID, @SyscomText; 

    WHILE @@fetch_status = 0 
    BEGIN 

        SELECT @BasePos = 1; 
        SELECT @CurrentPos = 1; 
        SELECT @TextLength = LEN(@SyscomText); 

        IF @ObjID &lt;&gt; @OldTrigID 
        BEGIN 
            SET @LineID = 1; 
            SET @OldTrigID = @ObjID; 
        END; 

        WHILE @CurrentPos != 0 
        BEGIN 
            --Looking for end of line followed by carriage return         
            SELECT @CurrentPos = CHARINDEX(CHAR(13) + CHAR(10), @SyscomText, @BasePos); 

            --If carriage return found         
            IF @CurrentPos != 0 
            BEGIN 

                WHILE ( ISNULL(LEN(@Line), 0) + @BlankSpaceAdded + @CurrentPos - @BasePos + @LFCR ) &gt; @DefinedLength 
                BEGIN 
                    SELECT @AddOnLen = @DefinedLength - (ISNULL(LEN(@Line), 0) + @BlankSpaceAdded ); 

                    INSERT 
                        @TrigText 
                    VALUES 
                        ( @ObjID, @LineId, ISNULL(@Line, N'') + ISNULL(SUBSTRING(@SyscomText, @BasePos, @AddOnLen), N'')); 

                    SELECT 
                        @Line = NULL, 
                        @LineId = @LineId + 1, 
                        @BasePos = @BasePos + @AddOnLen, 
                        @BlankSpaceAdded = 0; 
                END; 

                SELECT @Line = ISNULL(@Line, N'') + ISNULL(SUBSTRING(@SyscomText, @BasePos, @CurrentPos - @BasePos + @LFCR), N''); 

                SELECT @BasePos = @CurrentPos + 2; 

                INSERT 
                    @TrigText 
                VALUES
                    ( @ObjID, @LineId, @Line ); 

                SELECT @LineId = @LineId + 1; 

                SELECT @Line = NULL; 
            END; 
            ELSE 
            --else carriage return not found         
            BEGIN 
                IF @BasePos &lt;= @TextLength 
                BEGIN 
                    /*If new value for @Lines length will be &gt; then the         
                    **defined length         
                    */ 
                    WHILE ( ISNULL(LEN(@Line), 0) + @BlankSpaceAdded + @TextLength - @BasePos + 1 ) &gt; @DefinedLength 
                    BEGIN 
                        SELECT @AddOnLen = @DefinedLength - ( ISNULL(LEN(@Line), 0 ) + @BlankSpaceAdded ); 

                        INSERT 
                            @TrigText 
                        VALUES 
                            ( @ObjID, @LineId, ISNULL(@Line, N'') + ISNULL(SUBSTRING(@SyscomText, @BasePos, @AddOnLen), N'')); 

                        SELECT 
                            @Line = NULL, 
                            @LineId = @LineId + 1, 
                            @BasePos = @BasePos + @AddOnLen, 
                            @BlankSpaceAdded = 0; 
                    END; 

                    SELECT @Line = ISNULL(@Line, N'') + ISNULL(SUBSTRING(@SyscomText, @BasePos, @TextLength - @BasePos+1 ), N''); 

                    IF LEN(@Line) &lt; @DefinedLength AND CHARINDEX(' ', @SyscomText, @TextLength + 1) &gt; 0 
                    BEGIN 
                        SELECT 
                            @Line = @Line + ' ', 
                            @BlankSpaceAdded = 1; 
                    END; 
                END; 
            END; 
        END; 

        FETCH NEXT FROM ms_crs_syscom INTO @ObjID, @SyscomText; 
    END; 

    IF @Line IS NOT NULL 
        INSERT 
            @TrigText 
        VALUES
            ( @ObjID, @LineId, @Line ); 

    CLOSE ms_crs_syscom; 

    insert into @script select '-- You should run this result under dbo if your triggers belong to multiple users'; 
    insert into @script select ''; 

    IF @ScriptMode = 2 
    BEGIN 

        insert into @script select '-- Dropping the Triggers'; 
        insert into @script select ''; 

        insert into @script 
        SELECT 
            'IF EXISTS(SELECT * FROM sysobjects WHERE id = OBJECT_ID(''[' + username + '].[' + trigname + ']'')'
            + ' AND ObjectProperty(OBJECT_ID(''[' + username + '].[' + trigname + ']''), ''ISTRIGGER'') = 1)'
            + ' DROP TRIGGER [' + username + '].[' + trigname +']' + CHAR(13) + CHAR(10) 
            + 'GO' + CHAR(13) + CHAR(10)
        FROM   
            @Triggers; 
    END; 

    IF @ScriptMode = 0
    BEGIN   
        update 
            @TrigText 
        set 
            linetext = replace(linetext, 'CREATE TRIGGER', 'ALTER TRIGGER') 
        WHERE 
            upper(left(replace(ltrim(linetext), char(9), ''), 14)) = 'CREATE TRIGGER' 
    END

    insert into @script select '----------------------------------------------'; 
    insert into @script select '-- Creation of Triggers'; 
    insert into @script select ''; 
    insert into @script select ''; 

    DECLARE ms_users CURSOR LOCAL forward_only FOR 
    SELECT 
        T.username, 
        T.objid, 
        MAX(D.lineid) 
    FROM   
        @Triggers T, 
        @TrigText D 
    WHERE  
        T.objid = D.objid 
    GROUP BY    
        T.username, 
        T.objid 
    FOR READ ONLY; 

    OPEN ms_users; 

    FETCH NEXT FROM ms_users INTO @UserName, @ObjID, @MaxID; 

    WHILE @@fetch_status = 0 
    BEGIN 

        insert into @script select 'setuser N''' + @UserName + '''' + CHAR(13) + CHAR(10); 

        insert into @script 
        SELECT 
            '-- Text of the Trigger' = 
            CASE lineid 
                WHEN 1 THEN 'GO' + CHAR(13) + CHAR(10) + linetext 
                WHEN @MaxID THEN linetext + 'GO' 
                ELSE linetext 
            END 
        FROM   
            @TrigText 
        WHERE  
            objid = @ObjID 
        ORDER  
            BY lineid; 

        insert into @script select 'setuser'; 

        FETCH NEXT FROM ms_users INTO @UserName, @ObjID, @MaxID; 
    END; 

    CLOSE ms_users; 

    insert into @script select 'GO'; 
    insert into @script select '------End ------'; 

    DEALLOCATE ms_crs_syscom; 
    DEALLOCATE ms_users; 

    select script from @script order by id

END


--Use of the Procedure 

EXEC dbo.SYS_ScriptAllTriggers</code></pre>
<p>When you create and run the procedure, you will get a result like the one below.</p>
<p><img decoding="async" loading="lazy" class="alignnone wp-image-277 size-full" src="https://mssqlquery.com/wp-content/uploads/2021/11/procedure-to-show-script-of-all-triggers-in-sql-server-1.jpg" alt="Procedure to Show Script of All Triggers in SQL Server" width="700" height="574" srcset="https://mssqlquery.com/wp-content/uploads/2021/11/procedure-to-show-script-of-all-triggers-in-sql-server-1.jpg 700w, https://mssqlquery.com/wp-content/uploads/2021/11/procedure-to-show-script-of-all-triggers-in-sql-server-1-300x246.jpg 300w" sizes="(max-width: 700px) 100vw, 700px" /></p>
<p>As you can see, the script of all triggers has been created.</p>
<p>Good luck to everyone in business and life.</p>
<div class='epvc-post-count'><span class='epvc-eye'></span>  <span class="epvc-count"> 268</span><span class='epvc-label'> Views</span></div><p>The post <a href="https://mssqlquery.com/procedure-to-show-script-of-all-triggers-in-sql-server">Procedure to Show Script of All Triggers in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Enable All Triggers in SQL Server</title>
		<link>https://mssqlquery.com/enable-all-triggers-in-sql-server</link>
		
		<dc:creator><![CDATA[Yavuz Selim Kart]]></dc:creator>
		<pubDate>Mon, 01 Nov 2021 19:50:04 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Triggers]]></category>
		<category><![CDATA[Enable All Triggers in SQL Server]]></category>
		<category><![CDATA[SQL Enable Triggers]]></category>
		<category><![CDATA[TSQL Enable Triggers]]></category>
		<guid isPermaLink="false">https://mssqlquery.com/?p=201</guid>

					<description><![CDATA[<p>Hello to everyone, In this article, I will give information about how to enable All Triggers in SQL Server. In SQL Server, in some cases, you may want to enable all triggers. You can do this easily with the help of the code below. --Enable All Triggers in SQL Server&#46;&#46;&#46;</p>
<p>The post <a href="https://mssqlquery.com/enable-all-triggers-in-sql-server">Enable All Triggers in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Hello to everyone,</p>
<p>In this article,</p>
<p>I will give information about how to enable All Triggers in SQL Server.</p>
<p>In SQL Server, in some cases, you may want to enable all triggers.</p>
<p>You can do this easily with the help of the code below.</p>
<pre class="line-numbers"><code class="language-sql">--Enable All Triggers in SQL Server  

sp_msforeachtable 'ALTER TABLE ? ENABLE TRIGGER all'

--Let's check the triggers 

SELECT name AS TriggerName,
       is_disabled AS DisabledStatus
FROM sys.triggers
WHERE type = 'TR';</code></pre>
<p>When you run the code, you will get a result like the one below.</p>
<p><img decoding="async" loading="lazy" class="alignnone wp-image-203 size-full" src="https://mssqlquery.com/wp-content/uploads/2021/10/enable-all-triggers-in-sql-server-1.jpg" alt="Enable All Triggers in SQL Server" width="700" height="446" srcset="https://mssqlquery.com/wp-content/uploads/2021/10/enable-all-triggers-in-sql-server-1.jpg 700w, https://mssqlquery.com/wp-content/uploads/2021/10/enable-all-triggers-in-sql-server-1-300x191.jpg 300w" sizes="(max-width: 700px) 100vw, 700px" /></p>
<p>As you can see, all triggers are enabled.</p>
<p>Good luck to everyone in business and life.</p>
<div class='epvc-post-count'><span class='epvc-eye'></span>  <span class="epvc-count"> 247</span><span class='epvc-label'> Views</span></div><p>The post <a href="https://mssqlquery.com/enable-all-triggers-in-sql-server">Enable All Triggers in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Disable All Triggers in SQL Server</title>
		<link>https://mssqlquery.com/disable-all-triggers-in-sql-server</link>
		
		<dc:creator><![CDATA[Yavuz Selim Kart]]></dc:creator>
		<pubDate>Sun, 31 Oct 2021 20:48:26 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Triggers]]></category>
		<category><![CDATA[Disable All Triggers]]></category>
		<category><![CDATA[Disable All Triggers in SQL Server]]></category>
		<category><![CDATA[SQL Disable All Triggers]]></category>
		<guid isPermaLink="false">https://mssqlquery.com/?p=192</guid>

					<description><![CDATA[<p>Hello to everyone, In this article, I will give information about how to disable All Triggers in SQL Server. In SQL Server, in some cases, you may want to disable all triggers. You can do this easily with the help of the code below. --Disable All Triggers in SQL Server&#46;&#46;&#46;</p>
<p>The post <a href="https://mssqlquery.com/disable-all-triggers-in-sql-server">Disable All Triggers in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Hello to everyone,</p>
<p>In this article,</p>
<p>I will give information about how to disable All Triggers in SQL Server.</p>
<p>In SQL Server, in some cases, you may want to disable all triggers.</p>
<p>You can do this easily with the help of the code below.</p>
<pre class="line-numbers"><code class="language-sql">--Disable All Triggers in SQL Server  

sp_MSforeachtable 'ALTER TABLE ? DISABLE TRIGGER all';

--Let's check the triggers 

SELECT name AS TriggerName,
       is_disabled AS DisabledStatus
FROM sys.triggers
WHERE type = 'TR';</code></pre>
<p>When you run the code, you will get a result like the one below.</p>
<p><img decoding="async" loading="lazy" class="alignnone wp-image-194 size-full" src="https://mssqlquery.com/wp-content/uploads/2021/10/disable-all-triggers-in-sql-server-1.jpg" alt="Disable All Triggers in SQL Server " width="700" height="477" srcset="https://mssqlquery.com/wp-content/uploads/2021/10/disable-all-triggers-in-sql-server-1.jpg 700w, https://mssqlquery.com/wp-content/uploads/2021/10/disable-all-triggers-in-sql-server-1-300x204.jpg 300w" sizes="(max-width: 700px) 100vw, 700px" /></p>
<p>As you can see, all triggers are disabled.</p>
<p>Good luck to everyone in business and life.</p>
<div class='epvc-post-count'><span class='epvc-eye'></span>  <span class="epvc-count"> 229</span><span class='epvc-label'> Views</span></div><p>The post <a href="https://mssqlquery.com/disable-all-triggers-in-sql-server">Disable All Triggers in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Listing All Triggers in SQL Server</title>
		<link>https://mssqlquery.com/listing-all-triggers-in-sql-server</link>
		
		<dc:creator><![CDATA[Yavuz Selim Kart]]></dc:creator>
		<pubDate>Mon, 25 Oct 2021 16:40:54 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Triggers]]></category>
		<category><![CDATA[Listing All Triggers in SQL Server]]></category>
		<category><![CDATA[SQL All Triggers List]]></category>
		<category><![CDATA[TSQL Trigger List]]></category>
		<guid isPermaLink="false">https://mssqlquery.com/?p=187</guid>

					<description><![CDATA[<p>Hello to everyone, In this article, I will give information about how to list All Triggers in SQL Server. In SQL Server you may want to list all Triggers in some cases. You can do this easily with the help of the code below. SELECT name AS TriggerName, is_disabled AS&#46;&#46;&#46;</p>
<p>The post <a href="https://mssqlquery.com/listing-all-triggers-in-sql-server">Listing All Triggers in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Hello to everyone,</p>
<p>In this article, I will give information about how to list All Triggers in SQL Server.</p>
<p>In SQL Server you may want to list all Triggers in some cases.</p>
<p>You can do this easily with the help of the code below.</p>
<pre class="line-numbers"><code class="language-sql">SELECT  
    name AS TriggerName,
	is_disabled AS DisabledStatus    
FROM 
    sys.triggers  
WHERE 
    type = 'TR';</code></pre>
<p>When you run the code, you will get a result like the one below.</p>
<p><img decoding="async" loading="lazy" class="alignnone wp-image-190 size-full" src="https://mssqlquery.com/wp-content/uploads/2021/10/listing-all-triggers-in-sql-server-1.jpg" alt="Listing All Triggers in SQL Server" width="700" height="566" srcset="https://mssqlquery.com/wp-content/uploads/2021/10/listing-all-triggers-in-sql-server-1.jpg 700w, https://mssqlquery.com/wp-content/uploads/2021/10/listing-all-triggers-in-sql-server-1-300x243.jpg 300w" sizes="(max-width: 700px) 100vw, 700px" /></p>
<p>As you can see, all triggers are listed.</p>
<p>Good luck to everyone in business and life.</p>
<div class='epvc-post-count'><span class='epvc-eye'></span>  <span class="epvc-count"> 327</span><span class='epvc-label'> Views</span></div><p>The post <a href="https://mssqlquery.com/listing-all-triggers-in-sql-server">Listing All Triggers in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
