<?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>Sequence object &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/sequence-object/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>Wed, 28 Feb 2018 03:26:35 +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 Interview: Difference between Sequence Object and Identity Column</title>
		<link>https://www.dbrnd.com/2018/03/sql-server-interview-difference-between-sequence-object-and-identity-column/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Thu, 08 Mar 2018 16:16:34 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server Interview]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[IDENT_CURRENT]]></category>
		<category><![CDATA[Identity Column]]></category>
		<category><![CDATA[SCOPE_IDENTITY]]></category>
		<category><![CDATA[Sequence object]]></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=4287</guid>

					<description><![CDATA[This is a common interview question for SQL Server Database Developer. SQL Database Developer must prepare for this. Sequence and identity, both used to generate an auto number, but the major difference is Identity is a table dependant and Sequence is independent of a table. A Sequence Object introduced in SQL Server 2012 and Identity [&#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%2F03%2Fsql-server-interview-difference-between-sequence-object-and-identity-column%2F&amp;linkname=SQL%20Server%20Interview%3A%20Difference%20between%20Sequence%20Object%20and%20Identity%20Column" 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%2F03%2Fsql-server-interview-difference-between-sequence-object-and-identity-column%2F&amp;linkname=SQL%20Server%20Interview%3A%20Difference%20between%20Sequence%20Object%20and%20Identity%20Column" 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%2F03%2Fsql-server-interview-difference-between-sequence-object-and-identity-column%2F&amp;linkname=SQL%20Server%20Interview%3A%20Difference%20between%20Sequence%20Object%20and%20Identity%20Column" 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%2F03%2Fsql-server-interview-difference-between-sequence-object-and-identity-column%2F&amp;linkname=SQL%20Server%20Interview%3A%20Difference%20between%20Sequence%20Object%20and%20Identity%20Column" 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%2F03%2Fsql-server-interview-difference-between-sequence-object-and-identity-column%2F&amp;linkname=SQL%20Server%20Interview%3A%20Difference%20between%20Sequence%20Object%20and%20Identity%20Column" 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%2F03%2Fsql-server-interview-difference-between-sequence-object-and-identity-column%2F&amp;linkname=SQL%20Server%20Interview%3A%20Difference%20between%20Sequence%20Object%20and%20Identity%20Column" 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%2F03%2Fsql-server-interview-difference-between-sequence-object-and-identity-column%2F&#038;title=SQL%20Server%20Interview%3A%20Difference%20between%20Sequence%20Object%20and%20Identity%20Column" data-a2a-url="https://www.dbrnd.com/2018/03/sql-server-interview-difference-between-sequence-object-and-identity-column/" data-a2a-title="SQL Server Interview: Difference between Sequence Object and Identity Column"></a></p><p>This is a common interview question for SQL Server Database Developer. SQL Database Developer must prepare for this.</p>
<p>Sequence and identity, both used to generate an auto number, but the major difference is Identity is a table dependant and Sequence is independent of a table.</p>
<blockquote><p>A Sequence Object introduced in SQL Server 2012 and Identity column introduced in SQL Server 6.0.</p></blockquote>
<blockquote><p>A Sequence is a User defined object and Identity column is a table property. </p></blockquote>
<blockquote><p> The same Sequence object can use with the multiple tables. The same Identity column cannot use with multiple tables, we can define identity column on each table individually. </p></blockquote>
<blockquote><p>If you define the same Sequence Object to multiple tables, it generates the sequence number database-wide and maintains a unique sequence number across the multiple tables. An Identity column generates a unique number at table only.</p></blockquote>
<blockquote><p>Sequence syntax (Start with 1 and Increment by 1):</p>
<pre class="crayon-plain-tag">CREATE SEQUENCE
  dbo.Sequence_Name AS INT
 START WITH 1
 INCREMENT BY 1
GO</pre> </p>
<p>Identity syntax (Start with 1 and Increment by 1):</p>
<pre class="crayon-plain-tag">CREATE TABLE dbo.Table_Name
( Id INT IDENTITY(1,1),
  Name VARCHAR(50) )
GO</pre>
</p></blockquote>
<blockquote><p>Check the next value of Sequence object:</p>
<pre class="crayon-plain-tag">SELECT (NEXT VALUE FOR dbo.Sequence_Name) AS SeqNextValue</pre> </p>
<p>Check the next value of Identity Column:</p>
<pre class="crayon-plain-tag">SELECT SCOPE_IDENTITY()</pre>
(write after use of Identity column)
</p></blockquote>
<blockquote><p>
Check the current value of Sequence Object:</p>
<pre class="crayon-plain-tag">SELECT Current_Value 
FROM Sys.Sequences 
WHERE name='Sequence_Name'</pre> </p>
<p>Check the current value of Identity Column:</p>
<pre class="crayon-plain-tag">SELECT IDENT_CURRENT('Table_Name') 
 AS 'IdentityCurrentValue'</pre>
</p></blockquote>
<blockquote><p>You can modify a Sequence object using ALTER Statement.</p>
<pre class="crayon-plain-tag">ALTER SEQUENCE dbo.Sequence_Name
RESTART WITH 100
INCREMENT BY 5
GO</pre> </p>
<p>You can only reset the value of an Identity column using DBCC CHECKIDENT().</p>
<pre class="crayon-plain-tag">DBCC CHECKIDENT('Table_Name', RESEED,100)</pre>
</p></blockquote>
<blockquote><p>In Sequence New values can be generated in an UPDATE statement, but in Identity new value cannot be generated in an UPDATE statement.</p></blockquote>
<blockquote><p>You can define a maximum value for Sequence Object (Using MAXVALUE). You cannot provide a maximum value to Identity Column.</p></blockquote>
<blockquote><p>Once your Sequence object reached to MAXVALUE, you can also define a CYCLE option to restart it from the beginning. You cannot restart an Identity column value.</p></blockquote>
<blockquote><p>You can also enable data CACHE for a Sequence Object. You cannot enable data CACHE for an Identity Column and it uses table related data cache. </p></blockquote>
<blockquote><p>A User must require an access permission for Sequence Object. For Identity column, User requires only table related permissions. </p></blockquote>
<blockquote><p>Performance wise, Identity column is 3x faster than Sequence object.</p></blockquote>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>PostgreSQL: Script to find Orphaned Sequence, not owned by any Column</title>
		<link>https://www.dbrnd.com/2017/04/postgresql-script-to-find-orphaned-sequence-not-owned-by-any-column-dba-can-remove-unwanted-sequence/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 03 Apr 2017 16:16:28 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[PostgreSQL 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[orphan sequence]]></category>
		<category><![CDATA[pg_class]]></category>
		<category><![CDATA[pg_depend]]></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[Sequence object]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=3818</guid>

					<description><![CDATA[In this post, I am sharing a script to find orphaned Sequence objects which not owned by any column of PostgreSQL Database. When we define a column using SERIAL or BIGSERIAL, PostgreSQL internally creates one sequence for it and associate with it. In RDBMS, A Sequence is an independent object, and you can use same [&#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%2F04%2Fpostgresql-script-to-find-orphaned-sequence-not-owned-by-any-column-dba-can-remove-unwanted-sequence%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20find%20Orphaned%20Sequence%2C%20not%20owned%20by%20any%20Column" 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%2F04%2Fpostgresql-script-to-find-orphaned-sequence-not-owned-by-any-column-dba-can-remove-unwanted-sequence%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20find%20Orphaned%20Sequence%2C%20not%20owned%20by%20any%20Column" 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%2F04%2Fpostgresql-script-to-find-orphaned-sequence-not-owned-by-any-column-dba-can-remove-unwanted-sequence%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20find%20Orphaned%20Sequence%2C%20not%20owned%20by%20any%20Column" 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%2F04%2Fpostgresql-script-to-find-orphaned-sequence-not-owned-by-any-column-dba-can-remove-unwanted-sequence%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20find%20Orphaned%20Sequence%2C%20not%20owned%20by%20any%20Column" 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%2F04%2Fpostgresql-script-to-find-orphaned-sequence-not-owned-by-any-column-dba-can-remove-unwanted-sequence%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20find%20Orphaned%20Sequence%2C%20not%20owned%20by%20any%20Column" 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%2F04%2Fpostgresql-script-to-find-orphaned-sequence-not-owned-by-any-column-dba-can-remove-unwanted-sequence%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20find%20Orphaned%20Sequence%2C%20not%20owned%20by%20any%20Column" 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%2F04%2Fpostgresql-script-to-find-orphaned-sequence-not-owned-by-any-column-dba-can-remove-unwanted-sequence%2F&#038;title=PostgreSQL%3A%20Script%20to%20find%20Orphaned%20Sequence%2C%20not%20owned%20by%20any%20Column" data-a2a-url="https://www.dbrnd.com/2017/04/postgresql-script-to-find-orphaned-sequence-not-owned-by-any-column-dba-can-remove-unwanted-sequence/" data-a2a-title="PostgreSQL: Script to find Orphaned Sequence, not owned by any Column"></a></p><p>In this post, I am sharing a script to find orphaned Sequence objects which not owned by any column of PostgreSQL Database. </p>
<blockquote><p>When we define a column using SERIAL or BIGSERIAL, PostgreSQL internally creates one sequence for it and associate with it.<br />
In RDBMS, A Sequence is an independent object, and you can use same sequence object for multiple tables as well. </p></blockquote>
<blockquote><p>In a development environment, we are executing DDL frequently commands like multiple CREATE or DROP statements, so there is possibility of Orphaned Sequence. </p></blockquote>
<p>A Database Administrator can use this script to remove unwanted Sequence and make sure that Postgres database is up to date.</p><pre class="crayon-plain-tag">SELECT 
	ns.nspname AS SchemaName
	,c.relname AS SequenceName
FROM pg_class AS c
JOIN pg_namespace AS ns 
	ON c.relnamespace=ns.oid
WHERE c.relkind = 'S'
  AND NOT EXISTS (SELECT * FROM pg_depend WHERE objid=c.oid AND deptype='a')
ORDER BY c.relname;</pre><p> </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SQL Server 2012: Create Sequence object to generate Alphanumeric Sequence Number</title>
		<link>https://www.dbrnd.com/2016/02/sql-server-2012-create-sequence-object-to-generate-alphanumeric-sequence-number/</link>
					<comments>https://www.dbrnd.com/2016/02/sql-server-2012-create-sequence-object-to-generate-alphanumeric-sequence-number/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Wed, 03 Feb 2016 19:12:30 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Alphanumeric Sequence]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[Sequence object]]></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=1445</guid>

					<description><![CDATA[SQL Server 2012 introduced a Sequence object with lots of functionality, but unfortunately, we can only create Sequence Object with Number data-types. We can create a Sequence object for a list of below data-types: tinyint smallint int bigint decimal numeric But in some situations, we also require alphanumeric Sequence Number, and for that, we should [&#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%2F02%2Fsql-server-2012-create-sequence-object-to-generate-alphanumeric-sequence-number%2F&amp;linkname=SQL%20Server%202012%3A%20Create%20Sequence%20object%20to%20generate%20Alphanumeric%20Sequence%20Number" 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%2F02%2Fsql-server-2012-create-sequence-object-to-generate-alphanumeric-sequence-number%2F&amp;linkname=SQL%20Server%202012%3A%20Create%20Sequence%20object%20to%20generate%20Alphanumeric%20Sequence%20Number" 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%2F02%2Fsql-server-2012-create-sequence-object-to-generate-alphanumeric-sequence-number%2F&amp;linkname=SQL%20Server%202012%3A%20Create%20Sequence%20object%20to%20generate%20Alphanumeric%20Sequence%20Number" 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%2F02%2Fsql-server-2012-create-sequence-object-to-generate-alphanumeric-sequence-number%2F&amp;linkname=SQL%20Server%202012%3A%20Create%20Sequence%20object%20to%20generate%20Alphanumeric%20Sequence%20Number" 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%2F02%2Fsql-server-2012-create-sequence-object-to-generate-alphanumeric-sequence-number%2F&amp;linkname=SQL%20Server%202012%3A%20Create%20Sequence%20object%20to%20generate%20Alphanumeric%20Sequence%20Number" 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%2F02%2Fsql-server-2012-create-sequence-object-to-generate-alphanumeric-sequence-number%2F&amp;linkname=SQL%20Server%202012%3A%20Create%20Sequence%20object%20to%20generate%20Alphanumeric%20Sequence%20Number" 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%2F02%2Fsql-server-2012-create-sequence-object-to-generate-alphanumeric-sequence-number%2F&#038;title=SQL%20Server%202012%3A%20Create%20Sequence%20object%20to%20generate%20Alphanumeric%20Sequence%20Number" data-a2a-url="https://www.dbrnd.com/2016/02/sql-server-2012-create-sequence-object-to-generate-alphanumeric-sequence-number/" data-a2a-title="SQL Server 2012: Create Sequence object to generate Alphanumeric Sequence Number"></a></p><p>SQL Server 2012 introduced a Sequence object with lots of functionality, but unfortunately, we can only create Sequence Object with Number data-types.</p>
<p><strong>We can create a Sequence object for a list of below data-types:</strong></p>
<blockquote><p>tinyint<br />
	smallint<br />
	int<br />
	bigint<br />
	decimal<br />
	numeric</p></blockquote>
<p><strong>But in some situations, we also require alphanumeric Sequence Number, and for that, we should apply special FORMAT on the value of Sequence Number.</strong></p>
<p>Below is a full demonstration to FORMAT a Sequence value and make it alphanumeric.</p>
<p><strong>First, Create sample table:</strong></p><pre class="crayon-plain-tag">CREATE TABLE dbo.tbl_TestVarcharSequence
(
	VarcharID VARCHAR(10)
	,Name VARCHAR(255)
	,CONSTRAINT pk_tbl_TestVarcharSequence_VarcharID PRIMARY KEY(VarcharID)
)
GO</pre><p>
<p><strong>Create a Sequence object:</strong></p><pre class="crayon-plain-tag">CREATE SEQUENCE dbo.seq_TestVarcharSequenceNumber AS 
INT START WITH 1
INCREMENT BY 1;
GO</pre><p>
<p><strong>Create Sequence constraint using FORMAT function:</strong></p><pre class="crayon-plain-tag">ALTER TABLE dbo.tbl_TestVarcharSequence
ADD CONSTRAINT seq_tbl_TestVarcharSequence_VarcharID DEFAULT 
FORMAT((NEXT VALUE FOR dbo.seq_TestVarcharSequenceNumber),'ABC000000#') 
FOR VarcharID;
GO</pre><p>
<p><strong>Insert few sample records:</strong></p>
<pre class="crayon-plain-tag">INSERT INTO dbo.tbl_TestVarcharSequence (Name) 
VALUES ('Anvesh'),('Alex'),('Roy'),('Bony')
GO</pre> </p>
<p><strong>The Result:</strong></p><pre class="crayon-plain-tag">SELECT * FROM dbo.tbl_TestVarcharSequence</pre><p>
<a href="https://www.dbrnd.com/wp-content/uploads/2016/02/SQLServerVarcharSequence.png" rel="attachment wp-att-1449"><img decoding="async" class="alignnone wp-image-1449 size-full" title="SQL Server Alphanumeric Sequence" src="https://www.dbrnd.com/wp-content/uploads/2016/02/SQLServerVarcharSequence.png" alt="SQL Server Alphanumeric Sequence" width="146" height="107" /></a></p>
<p>You can find Alphanumeric Sequence Number in the above result. </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2016/02/sql-server-2012-create-sequence-object-to-generate-alphanumeric-sequence-number/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
