Today, I received a query from one of my blog readers asking how to get the current value from a sequence ? He also mentioned to me that he usually uses given below (Database console command) script to get the current value from identity column.
DBCC CHECKIDENT ('Table Name', NORESEED)
So, do we have any DBCC command like this to get the current value from sequence object? Basically we do not have any DBCC command to get the current value from sequence same like identity but we do have work around to find it. Given below are the two methods to get the current value from any sequence object.
METHOD 1 :
In this method, you need to open SQL Server Management Studio and select the particular database and further select the sequence object in which current value is required. Then right click on it and browse its property to view the current value as shown in the image below.
METHOD 2 :
In this method, you need to open a NEW query window in SSMS and write the given below script to get the current value of sequence using sys.sequences (A new system view shipped in SQL Server 2012).
--This script is compatible with SQL Server 2012 and above. USE AdventureWorks2012 GO SELECT current_value FROM sys.sequences WHERE [name]='Seq_sample' --OUTPUT
Leave a Reply