<?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>Constraint &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/constraint/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>Fri, 29 Sep 2017 06:40:51 +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 2012: Error Msg 3729 Cannot DROP SEQUENCE because it is being referenced by Object</title>
		<link>https://www.dbrnd.com/2016/01/sql-server-2012-error-msg-3729-cannot-drop-sequence-because-it-is-being-referenced-by-object/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Wed, 27 Jan 2016 19:07:22 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[Constraint]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[sequence]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server 2012]]></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[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=1387</guid>

					<description><![CDATA[The database Sequence Object introduced in SQL Server 2012 and we can use and assign single Sequence object to multiple tables. In this post, I am sharing a script to find all dependencies of the SQL Server Sequence object so that we can drop a Sequence object quickly. Below is a small demonstration, in which [&#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%2F01%2Fsql-server-2012-error-msg-3729-cannot-drop-sequence-because-it-is-being-referenced-by-object%2F&amp;linkname=SQL%20Server%202012%3A%20Error%20Msg%203729%20Cannot%20DROP%20SEQUENCE%20because%20it%20is%20being%20referenced%20by%20Object" 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%2F01%2Fsql-server-2012-error-msg-3729-cannot-drop-sequence-because-it-is-being-referenced-by-object%2F&amp;linkname=SQL%20Server%202012%3A%20Error%20Msg%203729%20Cannot%20DROP%20SEQUENCE%20because%20it%20is%20being%20referenced%20by%20Object" 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%2F01%2Fsql-server-2012-error-msg-3729-cannot-drop-sequence-because-it-is-being-referenced-by-object%2F&amp;linkname=SQL%20Server%202012%3A%20Error%20Msg%203729%20Cannot%20DROP%20SEQUENCE%20because%20it%20is%20being%20referenced%20by%20Object" 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%2F01%2Fsql-server-2012-error-msg-3729-cannot-drop-sequence-because-it-is-being-referenced-by-object%2F&amp;linkname=SQL%20Server%202012%3A%20Error%20Msg%203729%20Cannot%20DROP%20SEQUENCE%20because%20it%20is%20being%20referenced%20by%20Object" 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%2F01%2Fsql-server-2012-error-msg-3729-cannot-drop-sequence-because-it-is-being-referenced-by-object%2F&amp;linkname=SQL%20Server%202012%3A%20Error%20Msg%203729%20Cannot%20DROP%20SEQUENCE%20because%20it%20is%20being%20referenced%20by%20Object" 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%2F01%2Fsql-server-2012-error-msg-3729-cannot-drop-sequence-because-it-is-being-referenced-by-object%2F&amp;linkname=SQL%20Server%202012%3A%20Error%20Msg%203729%20Cannot%20DROP%20SEQUENCE%20because%20it%20is%20being%20referenced%20by%20Object" 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%2F01%2Fsql-server-2012-error-msg-3729-cannot-drop-sequence-because-it-is-being-referenced-by-object%2F&#038;title=SQL%20Server%202012%3A%20Error%20Msg%203729%20Cannot%20DROP%20SEQUENCE%20because%20it%20is%20being%20referenced%20by%20Object" data-a2a-url="https://www.dbrnd.com/2016/01/sql-server-2012-error-msg-3729-cannot-drop-sequence-because-it-is-being-referenced-by-object/" data-a2a-title="SQL Server 2012: Error Msg 3729 Cannot DROP SEQUENCE because it is being referenced by Object"></a></p><p>The database Sequence Object introduced in SQL Server 2012 and we can use and assign single Sequence object to multiple tables.</p>
<p>In this post, I am sharing a script to find all dependencies of the SQL Server Sequence object so that we can drop a Sequence object quickly.</p>
<p>Below is a small demonstration, in which I created a Sequence object and assigned to two different tables.</p>
<p><strong>Create a Sequence object:</strong></p><pre class="crayon-plain-tag">CREATE SEQUENCE dbo.Seq_Sample AS
INT START WITH 1
INCREMENT BY 1 ;
GO</pre><p>
<p><strong>Create two different tables:</strong></p><pre class="crayon-plain-tag">CREATE TABLE dbo.tbl_FirstSample
( 
	Rno INT
	,Name VARCHAR(255)
)
GO

CREATE TABLE dbo.tbl_SecSample
( 
	EmpID INT
	,EmpName VARCHAR(255)
)
GO</pre><p>
<p><strong>Assign Sequence object to both the tables:</strong></p><pre class="crayon-plain-tag">ALTER TABLE dbo.tbl_FirstSample
ADD CONSTRAINT seq_tbl_FirstSample_Rno
DEFAULT (NEXT VALUE FOR dbo.Seq_Sample) FOR Rno;
GO

ALTER TABLE dbo.tbl_SecSample
ADD CONSTRAINT seq_tbl_SecSample_EmpID
DEFAULT (NEXT VALUE FOR dbo.Seq_Sample) FOR EmpID;
GO</pre><p>
<p><strong>Now, try to drop the Sequence object:</strong></p><pre class="crayon-plain-tag">DROP SEQUENCE dbo.Seq_Sample
GO</pre><p>
<p><strong>You will get a below error:</strong></p>
<p><a href="https://www.dbrnd.com/wp-content/uploads/2016/01/SQLServerSequenceError.png" rel="attachment wp-att-1391"><img decoding="async" class="alignnone wp-image-1391 size-full" title="SQL Server Sequence Object Error" src="https://www.dbrnd.com/wp-content/uploads/2016/01/SQLServerSequenceError.png" alt="SQL Server Sequence Error" width="774" height="44" srcset="https://www.dbrnd.com/wp-content/uploads/2016/01/SQLServerSequenceError.png 774w, https://www.dbrnd.com/wp-content/uploads/2016/01/SQLServerSequenceError-300x17.png 300w, https://www.dbrnd.com/wp-content/uploads/2016/01/SQLServerSequenceError-768x44.png 768w, https://www.dbrnd.com/wp-content/uploads/2016/01/SQLServerSequenceError-750x43.png 750w, https://www.dbrnd.com/wp-content/uploads/2016/01/SQLServerSequenceError-150x9.png 150w" sizes="(max-width: 774px) 100vw, 774px" /></a></p>
<p><strong>Script to find and generate Alter command for all the dependencies:</strong></p><pre class="crayon-plain-tag">SELECT
	'ALTER TABLE '
	+ object_name(parent_object_id)
	+ ' DROP CONSTRAINT '
	+ referencing_entity_name AS AlterCommands
FROM sys.dm_sql_referencing_entities ('dbo.Seq_Sample', 'OBJECT') AS DR
INNER JOIN sys.default_constraints AS DC
    ON DR.referencing_id=DC.object_id
GO</pre><p>
<p><strong>The result:</strong></p>
<p><a href="https://www.dbrnd.com/wp-content/uploads/2016/01/SQLServerSequenceDropConstraint.png" rel="attachment wp-att-1392"><img decoding="async" class="alignnone wp-image-1392 size-full" title="SQL Server Sequence Drop Constraint" src="https://www.dbrnd.com/wp-content/uploads/2016/01/SQLServerSequenceDropConstraint.png" alt="SQL Server Sequence Drop Constraint" width="523" height="81" srcset="https://www.dbrnd.com/wp-content/uploads/2016/01/SQLServerSequenceDropConstraint.png 523w, https://www.dbrnd.com/wp-content/uploads/2016/01/SQLServerSequenceDropConstraint-300x46.png 300w, https://www.dbrnd.com/wp-content/uploads/2016/01/SQLServerSequenceDropConstraint-150x23.png 150w" sizes="(max-width: 523px) 100vw, 523px" /></a></p>
<p>Before dropping a Sequence object, we should drop all Sequence object constraint so copy the above result and drop both constraints before dropping a Sequence object.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
