<?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>trigger &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/trigger/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dbrnd.com</link>
	<description>BIGData &#124; NoSQL &#124; MSSQL &#124; MySQL &#124; PostgreSQL</description>
	<lastBuildDate>Mon, 24 Jun 2019 19:42:10 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.6</generator>
	<item>
		<title>SQL Server: How to compare your objects between two Databases</title>
		<link>https://www.dbrnd.com/2019/08/sql-server-how-to-compare-your-objects-table-view-stored-procedure-trigger-constraint-between-two-databases/</link>
					<comments>https://www.dbrnd.com/2019/08/sql-server-how-to-compare-your-objects-table-view-stored-procedure-trigger-constraint-between-two-databases/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 05 Aug 2019 16:16:04 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server DBA Script]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[compare]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[foreign key]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[Primary key]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tunning]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[stored procedures]]></category>
		<category><![CDATA[tables]]></category>
		<category><![CDATA[trigger]]></category>
		<category><![CDATA[TSQL]]></category>
		<category><![CDATA[views]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4094</guid>

					<description><![CDATA[When we are working with different versions of database, database professionals are comparing the objects between databases of SQL Server. They must make sure about that all databases are in sync. Using this T-SQL Script, you can compare two databases and find a list of unmatched objects like: Constraints, Tables, Views, Stored Procedure, Triggers. Sample [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F08%2Fsql-server-how-to-compare-your-objects-table-view-stored-procedure-trigger-constraint-between-two-databases%2F&amp;linkname=SQL%20Server%3A%20How%20to%20compare%20your%20objects%20between%20two%20Databases" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F08%2Fsql-server-how-to-compare-your-objects-table-view-stored-procedure-trigger-constraint-between-two-databases%2F&amp;linkname=SQL%20Server%3A%20How%20to%20compare%20your%20objects%20between%20two%20Databases" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F08%2Fsql-server-how-to-compare-your-objects-table-view-stored-procedure-trigger-constraint-between-two-databases%2F&amp;linkname=SQL%20Server%3A%20How%20to%20compare%20your%20objects%20between%20two%20Databases" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F08%2Fsql-server-how-to-compare-your-objects-table-view-stored-procedure-trigger-constraint-between-two-databases%2F&amp;linkname=SQL%20Server%3A%20How%20to%20compare%20your%20objects%20between%20two%20Databases" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F08%2Fsql-server-how-to-compare-your-objects-table-view-stored-procedure-trigger-constraint-between-two-databases%2F&amp;linkname=SQL%20Server%3A%20How%20to%20compare%20your%20objects%20between%20two%20Databases" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F08%2Fsql-server-how-to-compare-your-objects-table-view-stored-procedure-trigger-constraint-between-two-databases%2F&amp;linkname=SQL%20Server%3A%20How%20to%20compare%20your%20objects%20between%20two%20Databases" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F08%2Fsql-server-how-to-compare-your-objects-table-view-stored-procedure-trigger-constraint-between-two-databases%2F&#038;title=SQL%20Server%3A%20How%20to%20compare%20your%20objects%20between%20two%20Databases" data-a2a-url="https://www.dbrnd.com/2019/08/sql-server-how-to-compare-your-objects-table-view-stored-procedure-trigger-constraint-between-two-databases/" data-a2a-title="SQL Server: How to compare your objects between two Databases"></a></p><p>When we are working with different versions of database, database professionals are comparing the objects between databases of SQL Server.<br />
They must make sure about that all databases are in sync. </p>
<blockquote><p>Using this T-SQL Script, you can compare two databases and find a list of unmatched objects like: Constraints, Tables, Views, Stored Procedure, Triggers. </p></blockquote>
<p><strong>Sample demonstration:</strong><br />
<strong>First, Create two sample databases:<br />
</strong></p>
<pre class="crayon-plain-tag">CREATE DATABASE ABC
GO
CREATE DATABASE XYZ
GO</pre> </p>
<p><strong>Create few sample tables in both the databases:<br />
</strong></p><pre class="crayon-plain-tag">CREATE TABLE ABC.dbo.tbl_Test
(
	ID INT
	,MyDate DATE
)
GO

CREATE TABLE ABC.dbo.tbl_MyTest
(
	ID INT
	,Name VARCHAR(50)
)
GO

CREATE TABLE XYZ.dbo.tbl_Test
(
	ID INT
	,MyDate DATE
)
GO

CREATE TABLE XYZ.dbo.tbl_MyFinal
(
	ID INT
	,Name VARCHAR(50)
)
GO</pre><p> </p>
<p><strong>T-SQL Script to compare objects between two databases:</strong><br />
According to your databases, You can change the name of @SourceDatabase and @DestinationDatabase.</p>
<pre class="crayon-plain-tag">DECLARE @SourceDatabase VARCHAR(50) 
DECLARE @DestinationDatabase VARCHAR(50) 
DECLARE @SQL VARCHAR(MAX) 
     
SELECT @SourceDatabase = 'ABC' 
SELECT @DestinationDatabase = 'XYZ'
     
SELECT @SQL = 
'
	SELECT 
		ISNULL(S.name,D.name) ObjectName
		,CASE  
			WHEN S.object_id IS NULL 
				THEN D.type_desc + '' is missing in the Source Database: '	+ @SourceDatabase + ''' 
			WHEN D.object_id IS NULL 
				THEN S.type_desc +  '' is missing in the Destination Database: ' + @DestinationDatabase + ''' 
		END ''Status'' 
	FROM 
	(
		SELECT * FROM ' + @SourceDatabase + '.SYS.objects  
		WHERE Type_desc not in (''INTERNAL_TABLE'',''SYSTEM_TABLE'',''SERVICE_QUEUE'')
	) AS S  
	FULL OUTER JOIN 
	(
		SELECT * FROM ' + @DestinationDatabase + '.SYS.objects  
		WHERE Type_desc not in (''INTERNAL_TABLE'',''SYSTEM_TABLE'',''SERVICE_QUEUE'')
	) AS D 
	ON S.name = D.name 
		AND S.type = D.type 
	ORDER BY isnull(S.type,D.type)
'  
EXEC (@Sql)</pre> </p>
<p><strong>The Result:</strong></p>
<pre class="crayon-plain-tag">ObjectName                         Status
------------------  -------------------------------------------------------
tbl_Test              NULL
tbl_MyFinal           USER_TABLE is missing in the Source Database: ABC
tbl_MyTest            USER_TABLE is missing in the Destination Database: XYZ</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2019/08/sql-server-how-to-compare-your-objects-table-view-stored-procedure-trigger-constraint-between-two-databases/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>SQL Server: Script to find the list of Triggers</title>
		<link>https://www.dbrnd.com/2018/10/sql-server-script-to-find-the-list-of-triggers/</link>
					<comments>https://www.dbrnd.com/2018/10/sql-server-script-to-find-the-list-of-triggers/#respond</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 29 Oct 2018 16:16:28 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server DBA Script]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[Audit Trigger]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[Drop Trigger]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Error]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tuning]]></category>
		<category><![CDATA[SQL Server Programming]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[trigger]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=7415</guid>

					<description><![CDATA[In this post, I am sharing a script for getting the list of Triggers in SQL Server. Periodically, we should do the auditing of database hidden triggers. Because triggers are not good for database performance especially for OLTP system. Many times developers are creating triggers for testing purpose and later forget to drop those. SQL [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F10%2Fsql-server-script-to-find-the-list-of-triggers%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20the%20list%20of%20Triggers" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F10%2Fsql-server-script-to-find-the-list-of-triggers%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20the%20list%20of%20Triggers" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F10%2Fsql-server-script-to-find-the-list-of-triggers%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20the%20list%20of%20Triggers" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F10%2Fsql-server-script-to-find-the-list-of-triggers%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20the%20list%20of%20Triggers" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F10%2Fsql-server-script-to-find-the-list-of-triggers%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20the%20list%20of%20Triggers" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F10%2Fsql-server-script-to-find-the-list-of-triggers%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20the%20list%20of%20Triggers" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F10%2Fsql-server-script-to-find-the-list-of-triggers%2F&#038;title=SQL%20Server%3A%20Script%20to%20find%20the%20list%20of%20Triggers" data-a2a-url="https://www.dbrnd.com/2018/10/sql-server-script-to-find-the-list-of-triggers/" data-a2a-title="SQL Server: Script to find the list of Triggers"></a></p><p>In this post, I am sharing a script for getting the list of Triggers in SQL Server. Periodically, we should do the auditing of database hidden triggers. </p>
<p>Because triggers are not good for database performance especially for OLTP system. Many times developers are creating triggers for testing purpose and later forget to drop those. </p>
<blockquote class="wp-embedded-content" data-secret="803rZKZCdm"><p><a href="https://www.dbrnd.com/2016/10/sql-server-encrypted-ddl-trigger-to-track-all-database-changes-to-ensure-database-object-security/">SQL Server: Encrypted DDL Trigger to Track all Database Changes</a></p></blockquote>
<p><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/10/sql-server-encrypted-ddl-trigger-to-track-all-database-changes-to-ensure-database-object-security/embed/#?secret=803rZKZCdm" data-secret="803rZKZCdm" width="600" height="338" title="&#8220;SQL Server: Encrypted DDL Trigger to Track all Database Changes&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p><strong>Execute the below script and get list of all triggers: </strong></p><pre class="crayon-plain-tag">SELECT 
	sysobjects.name AS TriggerName 
	,USER_NAME(sysobjects.uid) AS TriggerOwner 
	,s.name AS TableSchema 
	,OBJECT_NAME(parent_obj) AS TableName 
	,OBJECTPROPERTY( id, 'ExecIsUpdateTrigger') AS Isupdate 
	,OBJECTPROPERTY( id, 'ExecIsDeleteTrigger') AS Isdelete 
	,OBJECTPROPERTY( id, 'ExecIsInsertTrigger') AS Isinsert 
	,OBJECTPROPERTY( id, 'ExecIsAfterTrigger') AS Isafter 
	,OBJECTPROPERTY( id, 'ExecIsInsteadOfTrigger') AS Isinsteadof
	,OBJECTPROPERTY(id, 'ExecIsTriggerDisabled') AS Isdisabled
FROM sysobjects 
INNER JOIN sysusers 
    ON sysobjects.uid = sysusers.uid 
INNER JOIN sys.tables t 
    ON sysobjects.parent_obj = t.object_id 
INNER JOIN sys.schemas s 
    ON t.schema_id = s.schema_id 
WHERE sysobjects.type = 'TR'</pre><p> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2018/10/sql-server-script-to-find-the-list-of-triggers/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>PostgreSQL: How to Disable or Enable Foreign Key Constraint of a Table</title>
		<link>https://www.dbrnd.com/2017/02/postgresql-how-to-disable-or-enable-foreign-key-constraint-of-a-table-data-migration-bulk-operation/</link>
					<comments>https://www.dbrnd.com/2017/02/postgresql-how-to-disable-or-enable-foreign-key-constraint-of-a-table-data-migration-bulk-operation/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Thu, 02 Feb 2017 16:16:49 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[bulk operation]]></category>
		<category><![CDATA[data migration]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[Disable Foreign Key Constraint]]></category>
		<category><![CDATA[Foreign Key constraint]]></category>
		<category><![CDATA[plpgsql]]></category>
		<category><![CDATA[Postgres Query]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[PostgreSQL Administrator]]></category>
		<category><![CDATA[PostgreSQL Error]]></category>
		<category><![CDATA[PostgreSQL Performance Tuning]]></category>
		<category><![CDATA[PostgreSQL Programming]]></category>
		<category><![CDATA[PostgreSQL Tips and Tricks]]></category>
		<category><![CDATA[trigger]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=3939</guid>

					<description><![CDATA[In this post, I am sharing one option to Disable / Enable the Foreign Key Constraint in PostgreSQL. During data migration and testing purpose, Database Developer requires to disable Foreign key constraint of a Table. Once you disable constraint, then later you might need to enable again, but during this exercise make sure that all [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F02%2Fpostgresql-how-to-disable-or-enable-foreign-key-constraint-of-a-table-data-migration-bulk-operation%2F&amp;linkname=PostgreSQL%3A%20How%20to%20Disable%20or%20Enable%20Foreign%20Key%20Constraint%20of%20a%20Table" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F02%2Fpostgresql-how-to-disable-or-enable-foreign-key-constraint-of-a-table-data-migration-bulk-operation%2F&amp;linkname=PostgreSQL%3A%20How%20to%20Disable%20or%20Enable%20Foreign%20Key%20Constraint%20of%20a%20Table" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F02%2Fpostgresql-how-to-disable-or-enable-foreign-key-constraint-of-a-table-data-migration-bulk-operation%2F&amp;linkname=PostgreSQL%3A%20How%20to%20Disable%20or%20Enable%20Foreign%20Key%20Constraint%20of%20a%20Table" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F02%2Fpostgresql-how-to-disable-or-enable-foreign-key-constraint-of-a-table-data-migration-bulk-operation%2F&amp;linkname=PostgreSQL%3A%20How%20to%20Disable%20or%20Enable%20Foreign%20Key%20Constraint%20of%20a%20Table" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F02%2Fpostgresql-how-to-disable-or-enable-foreign-key-constraint-of-a-table-data-migration-bulk-operation%2F&amp;linkname=PostgreSQL%3A%20How%20to%20Disable%20or%20Enable%20Foreign%20Key%20Constraint%20of%20a%20Table" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F02%2Fpostgresql-how-to-disable-or-enable-foreign-key-constraint-of-a-table-data-migration-bulk-operation%2F&amp;linkname=PostgreSQL%3A%20How%20to%20Disable%20or%20Enable%20Foreign%20Key%20Constraint%20of%20a%20Table" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F02%2Fpostgresql-how-to-disable-or-enable-foreign-key-constraint-of-a-table-data-migration-bulk-operation%2F&#038;title=PostgreSQL%3A%20How%20to%20Disable%20or%20Enable%20Foreign%20Key%20Constraint%20of%20a%20Table" data-a2a-url="https://www.dbrnd.com/2017/02/postgresql-how-to-disable-or-enable-foreign-key-constraint-of-a-table-data-migration-bulk-operation/" data-a2a-title="PostgreSQL: How to Disable or Enable Foreign Key Constraint of a Table"></a></p><p>In this post, I am sharing one option to Disable / Enable the Foreign Key Constraint in PostgreSQL.</p>
<blockquote><p>During data migration and testing purpose, Database Developer requires to disable Foreign key constraint of a Table.</p></blockquote>
<blockquote><p>Once you disable constraint, then later you might need to enable again, but during this exercise make sure that all your data changes are correct.</p></blockquote>
<blockquote><p>PostgreSQL does not provide any direct command or function to disable / enable the Foreign key constraints. </p></blockquote>
<blockquote><p>When you create any Foreign Key on the table, internally It creates a hidden trigger for check data integrity.<br />
You should enable/disable the trigger for achieving disable foreign key constraint.</p></blockquote>
<p><strong>Create a sample Student Master table:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_Students 
(
	StudID INTEGER PRIMARY KEY
	,StudName CHARACTER VARYING
	,StudClass CHAR(1)	
);</pre> </p>
<p><strong>Insert few sample records in Student Master table:</strong></p>
<pre class="crayon-plain-tag">INSERT INTO tbl_Students 
VALUES (1,'Anvesh','A')
,(2,'Neevan','B'),(3,'Jenny','C')
,(4,'Roy','C'),(5,'Martin','C');</pre> </p>
<p><strong>Create a sample Student Marks table:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_StudentMarks
(
	StudentMarkID INTEGER PRIMARY KEY
	,StudID INTEGER 
	,Sub1Mark SMALLINT
	,Sub2Mark SMALLINT
	,Sub3Mark SMALLINT	
	,CONSTRAINT fk_tbl_StudentMarks_StudID FOREIGN KEY (StudID) REFERENCES tbl_Students (StudID)
);</pre> </p>
<p><strong>Try to insert data with StudID which does not belong to Student Master table:</strong></p>
<pre class="crayon-plain-tag">INSERT INTO tbl_StudentMarks 
VALUES (1,6,50,60,90);</pre> </p>
<p><strong>You will get a below error message:</strong></p>
<pre class="crayon-plain-tag">ERROR:  insert or update on table "tbl_studentmarks" violates foreign key constraint "fk_tbl_studentmarks_studid"
DETAIL:  Key (studid)=(6) is not present in table "tbl_students".
********** Error **********</pre> </p>
<p><strong>Disable all hidden triggers of a Student Mark table:</strong></p>
<pre class="crayon-plain-tag">ALTER TABLE tbl_StudentMarks DISABLE TRIGGER ALL;</pre> </p>
<p><strong>Now Again, try to insert same record:</strong></p>
<pre class="crayon-plain-tag">INSERT INTO tbl_StudentMarks 
VALUES (1,6,50,60,90);</pre> </p>
<p><strong>Once you did with your task, please enable all trigger of a table:</strong></p>
<pre class="crayon-plain-tag">ALTER TABLE tbl_StudentMarks ENABLE TRIGGER ALL;</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2017/02/postgresql-how-to-disable-or-enable-foreign-key-constraint-of-a-table-data-migration-bulk-operation/feed/</wfw:commentRss>
			<slash:comments>11</slash:comments>
		
		
			</item>
		<item>
		<title>PostgreSQL: How to increase the performance of Bulk Insertion (INSERT)</title>
		<link>https://www.dbrnd.com/2016/08/postgresql-how-to-increase-the-performance-of-bulk-insertion-insert-copy-command-disable-trigger-index-vacumming/</link>
					<comments>https://www.dbrnd.com/2016/08/postgresql-how-to-increase-the-performance-of-bulk-insertion-insert-copy-command-disable-trigger-index-vacumming/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Fri, 26 Aug 2016 18:13:34 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[checkpoint_segment]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[index]]></category>
		<category><![CDATA[insert]]></category>
		<category><![CDATA[optimized insertion]]></category>
		<category><![CDATA[plpgsql]]></category>
		<category><![CDATA[Postgres Query]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[PostgreSQL Administrator]]></category>
		<category><![CDATA[PostgreSQL Error]]></category>
		<category><![CDATA[PostgreSQL Programming]]></category>
		<category><![CDATA[PostgreSQL Tips and Tricks]]></category>
		<category><![CDATA[shared_buffers]]></category>
		<category><![CDATA[trigger]]></category>
		<category><![CDATA[work_mem]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=3562</guid>

					<description><![CDATA[This is one of the important post for all PostgreSQL Database Administrator who are dealing with Bulk Insertion in their PostgreSQL Server. We should optimize Bulk Insertion operation because It is also utilizing more system resources. Few steps to increase the performance of Bulk Insertion: If It is only one time data load, remove all [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F08%2Fpostgresql-how-to-increase-the-performance-of-bulk-insertion-insert-copy-command-disable-trigger-index-vacumming%2F&amp;linkname=PostgreSQL%3A%20How%20to%20increase%20the%20performance%20of%20Bulk%20Insertion%20%28INSERT%29" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F08%2Fpostgresql-how-to-increase-the-performance-of-bulk-insertion-insert-copy-command-disable-trigger-index-vacumming%2F&amp;linkname=PostgreSQL%3A%20How%20to%20increase%20the%20performance%20of%20Bulk%20Insertion%20%28INSERT%29" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F08%2Fpostgresql-how-to-increase-the-performance-of-bulk-insertion-insert-copy-command-disable-trigger-index-vacumming%2F&amp;linkname=PostgreSQL%3A%20How%20to%20increase%20the%20performance%20of%20Bulk%20Insertion%20%28INSERT%29" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F08%2Fpostgresql-how-to-increase-the-performance-of-bulk-insertion-insert-copy-command-disable-trigger-index-vacumming%2F&amp;linkname=PostgreSQL%3A%20How%20to%20increase%20the%20performance%20of%20Bulk%20Insertion%20%28INSERT%29" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F08%2Fpostgresql-how-to-increase-the-performance-of-bulk-insertion-insert-copy-command-disable-trigger-index-vacumming%2F&amp;linkname=PostgreSQL%3A%20How%20to%20increase%20the%20performance%20of%20Bulk%20Insertion%20%28INSERT%29" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F08%2Fpostgresql-how-to-increase-the-performance-of-bulk-insertion-insert-copy-command-disable-trigger-index-vacumming%2F&amp;linkname=PostgreSQL%3A%20How%20to%20increase%20the%20performance%20of%20Bulk%20Insertion%20%28INSERT%29" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F08%2Fpostgresql-how-to-increase-the-performance-of-bulk-insertion-insert-copy-command-disable-trigger-index-vacumming%2F&#038;title=PostgreSQL%3A%20How%20to%20increase%20the%20performance%20of%20Bulk%20Insertion%20%28INSERT%29" data-a2a-url="https://www.dbrnd.com/2016/08/postgresql-how-to-increase-the-performance-of-bulk-insertion-insert-copy-command-disable-trigger-index-vacumming/" data-a2a-title="PostgreSQL: How to increase the performance of Bulk Insertion (INSERT)"></a></p><p>This is one of the important post for all PostgreSQL Database Administrator who are dealing with Bulk Insertion in their PostgreSQL Server.</p>
<blockquote><p>We should optimize Bulk Insertion operation because It is also utilizing more system resources.</p></blockquote>
<p><strong>Few steps to increase the performance of Bulk Insertion:</strong></p>
<ul>
<li>If It is only one time data load, remove all Index and create after INSERT. For regular Bulk Insertion, look into Index part and try to optimize it.</li>
<li>Take a backup of all the Triggers and drop all the Triggers.</li>
<li>Use COPY command instead of INSERT.</li>
<li>If you can not use COPY command because of of INSERT multiple value, you should not give more than 1000 multiple values in single INSERT. All INSERT multiple values stored in the memory area which may decrease the INSERT performance.</li>
<li>Disable other database logging process.</li>
<li>If BULK INSERTION is running with a single transaction, you should also disable all FOREIGN KEYs and later you can enable it.</li>
<li>Change synchronous_commit=off to reduce the cost of committing.</li>
<li>Change Checkpoint default configuration, Increase the checkpoint_segments value.</li>
<li>Increase the size of shared_buffers, effective_cache_size, work_mem.</li>
<li>Prepared all statements on server side.</li>
<li>Disable Auto-Vacuum on Table.</li>
<li>Disable Auto Database Backup process.</li>
<li>Increase the system resource (Memory, Disk, CPU), If it is required.</li>
<li>Use SSD type of Disk for faster storage.</li>
</ul>
<p>Note: Whatever you changed for BULK INSERTION, please do not forget to rollback after completion of BULK INSERTION.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2016/08/postgresql-how-to-increase-the-performance-of-bulk-insertion-insert-copy-command-disable-trigger-index-vacumming/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>SQL Server: Script to find Status of all Database Trigger</title>
		<link>https://www.dbrnd.com/2015/12/sql-server-script-to-find-status-of-all-database-trigger/</link>
					<comments>https://www.dbrnd.com/2015/12/sql-server-script-to-find-status-of-all-database-trigger/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Wed, 30 Dec 2015 18:40:19 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server DBA Script]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tunning]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[trigger]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=1198</guid>

					<description><![CDATA[In this post, I am sharing an important TSQL Script to find the different status like Enable, Disable of a SQL Server Database Trigger. Database Trigger is a significant object because it is doing the operation in the background and manipulates defined DDL and DML commands. As a Database Administrator, this is our responsibility to [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F12%2Fsql-server-script-to-find-status-of-all-database-trigger%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20Status%20of%20all%20Database%20Trigger" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F12%2Fsql-server-script-to-find-status-of-all-database-trigger%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20Status%20of%20all%20Database%20Trigger" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F12%2Fsql-server-script-to-find-status-of-all-database-trigger%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20Status%20of%20all%20Database%20Trigger" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F12%2Fsql-server-script-to-find-status-of-all-database-trigger%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20Status%20of%20all%20Database%20Trigger" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F12%2Fsql-server-script-to-find-status-of-all-database-trigger%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20Status%20of%20all%20Database%20Trigger" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F12%2Fsql-server-script-to-find-status-of-all-database-trigger%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20Status%20of%20all%20Database%20Trigger" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F12%2Fsql-server-script-to-find-status-of-all-database-trigger%2F&#038;title=SQL%20Server%3A%20Script%20to%20find%20Status%20of%20all%20Database%20Trigger" data-a2a-url="https://www.dbrnd.com/2015/12/sql-server-script-to-find-status-of-all-database-trigger/" data-a2a-title="SQL Server: Script to find Status of all Database Trigger"></a></p><p>In this post, I am sharing an important TSQL Script to find the different status like Enable, Disable of a SQL Server Database Trigger. </p>
<p>Database Trigger is a significant object because it is doing the operation in the background and manipulates defined DDL and DML commands. </p>
<p>As a Database Administrator, this is our responsibility to find out the different status of all running Trigger of a SQL Server Database. </p>
<p><strong>Below is a script:</strong></p>
<pre class="crayon-plain-tag">SELECT
	[T].[name] AS TableName
	,[TR].[name] AS TriggerName
	,(CASE 
		WHEN OBJECTPROPERTY([TR].[object_id], 'ExecIsTriggerDisabled') =1 
		THEN 'DISABLED' ELSE 'ENABLED' 
	END) AS TriggerStatus
	 
	,(CASE 
		WHEN OBJECTPROPERTY([TR].[object_id], 'ExecIsInsertTrigger') =1 
		THEN 'No' ELSE 'Yes' 
	END) AS IsInsertTrigger
 
	,(CASE 
		WHEN OBJECTPROPERTY([TR].[object_id], 'ExecIsFirstInsertTrigger') =1 
		THEN 'No' ELSE 'Yes' 
	END) AS IsFirstInsertTrigger
 
	,(CASE 
		WHEN OBJECTPROPERTY([TR].[object_id], 'ExecIsLastInsertTrigger') =1 
		THEN 'No' ELSE 'Yes' 
	END) AS IsLAStInsertTrigger
 
	,(CASE 
		WHEN OBJECTPROPERTY([TR].[object_id], 'ExecIsDeleteTrigger') =1 
		THEN 'No' ELSE 'Yes' 
	END) AS IsDeleteTrigger
 
	,(CASE 
		WHEN OBJECTPROPERTY([TR].[object_id], 'ExecIsFirstDeleteTrigger') =1 
		THEN 'No' ELSE 'Yes' 
	END) AS IsFirstDeleteTrigger
 
	,(CASE 
		WHEN OBJECTPROPERTY([TR].[object_id], 'ExecIsLastDeleteTrigger') =1 
		THEN 'No' ELSE 'Yes' 
	END) AS IsLAStDeleteTrigger
 
	,(CASE 
		WHEN OBJECTPROPERTY([TR].[object_id], 'ExecIsUpdateTrigger') =1 
		THEN 'No' ELSE 'Yes' 
	END) AS IsUpdateTrigger
 
	,(CASE 
		WHEN OBJECTPROPERTY([TR].[object_id], 'ExecIsFirstUpdateTrigger') =1 
		THEN 'No' ELSE 'Yes' 
	END) AS IsFirstUpdateTrigger
 
	,(CASE 
		WHEN OBJECTPROPERTY([TR].[object_id], 'ExecIsLastUpdateTrigger') =1 
		THEN 'No' ELSE 'Yes' 
	END) AS IsLAStUpdateTrigger
 
	,(CASE 
		WHEN OBJECTPROPERTY([TR].[object_id], 'ExecIsAfterTrigger') =1 
		THEN 'No' ELSE 'Yes' 
	END) AS IsAfterTrigger
 
	,(CASE 
		WHEN OBJECTPROPERTY([TR].[object_id], 'ExecIsInsteadOfTrigger') =1 
		THEN 'No' ELSE 'Yes' 
	END) AS IsInsteadOfTrigger
 
	,(CASE 
		WHEN OBJECTPROPERTY([TR].[object_id], 'ExecIsTriggerNotForRepl') =1 
		THEN 'No' ELSE 'Yes' 
	END) AS IsTriggerNotForReplication 
FROM sys.tables AS T
INNER JOIN sys.triggers AS TR
	ON [T].[object_id]=[TR].[parent_id]</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2015/12/sql-server-script-to-find-status-of-all-database-trigger/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
	</channel>
</rss>
