March 6, 2014 at 8:34 pm
Hi,
I have created a Int column with Identity
It has almost reached max size of Int.
i need to again start from the first
Few older records are deleted , the id which starts with 1 to 10000000 (3 year old record)
can i have some mechanism like this inside the stored procedure
DECLARE @MaxID INT
SELECT @MaxID = MAX(ID)
FROM TableID
DBCC CHECKIDENT('TableID', RESEED, @MaxID)
if i add this command in my existing stored procedure will it affect the performance?
March 7, 2014 at 2:41 am
If you change your identity column to BIGINT, you won't have to deal with duplicate ID's. The point of an identity column is to uniquely identify each row, with the help of a unique index on that column. You defeat that point somewhat if you introduce duplicates. Does your table really have more than two thousand million rows or have you reseeded before/have lots of gaps in the sequence?
For better assistance in answering your questions, please read this[/url].
Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]
March 7, 2014 at 3:15 am
i would suggest to use Sequence in place of identity
March 7, 2014 at 3:20 am
yuvipoy (3/6/2014)
Hi,I have created a Int column with Identity
It has almost reached max size of Int.
i need to again start from the first
Few older records are deleted , the id which starts with 1 to 10000000 (3 year old record)
can i have some mechanism like this inside the stored procedure
DECLARE @MaxID INT
SELECT @MaxID = MAX(ID)
FROM TableID
DBCC CHECKIDENT('TableID', RESEED, @MaxID)
if i add this command in my existing stored procedure will it affect the performance?
Unless your current identity value is lower than the maximum ID present in the table, what is the point of reseeding with the maximum value? You'll quickly run against the same integer limit.
As Chris said, it is better to avoid duplicates and just change the datatype.
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
March 7, 2014 at 3:20 am
Sushil Dwivedi (3/7/2014)
i would suggest to use Sequence in place of identity
Because of which reasons?
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
March 7, 2014 at 3:34 am
I misread the question.I thought he is asking alternate of identity so I suggested Sequence because performance wise, Sequence is better than Identity and we don’t have limitation in sequence like we have in identity.
March 7, 2014 at 3:43 am
Sushil Dwivedi (3/7/2014)
performance wise, Sequence is better than Identity
Can you show your tests and benchmarks which show this performance improvement from sequence?
we don’t have limitation in sequence like we have in identity.
Limitations such as?
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
March 7, 2014 at 4:00 am
Are you testing me ...?
Limitation
1.Identity:- It's table dependent, you can apply identity on single table at a time. It is not a separate database object like Sequence.
Identity column is specific to a column of a table, where as sequences will an another DB object which can be associated with column of an n number of tables
If you inserting value into table and your transaction got failed,identity assigned value to failed transaction as well
like
1,2,3,4...failed... than it will not start from 5.. it will start from 6 when you will start insert again.
These limitation we don't have in Sequence.it will have start value,increment and end value
Performance :-
Tests with just three or four concurrent requests (used as a default and manually fetching values), they are faster than an identity column with default caching, and (unlike identity based columns) you have control over the caching, so you can tune to a higher number of pre-calculated values
March 7, 2014 at 4:08 am
Sushil Dwivedi (3/7/2014)
Are you testing me ...?Limitation
1.Identity:- It's table dependent, you can apply identity on single table at a time. It is not a separate database object like Sequence.
Identity column is specific to a column of a table, where as sequences will an another DB object which can be associated with column of an n number of tables
If you inserting value into table and your transaction got failed,identity assigned value to failed transaction as well
like
1,2,3,4...failed... than it will not start from 5.. it will start from 6 when you will start insert again.
These limitation we don't have in Sequence.it will have start value,increment and end value
If you are using IDENTITY just to have a unique ID field in your table (for example a surrogate key in a dimension table), I don't consider these limitations at all. IDENTITY is table dependent yes, but that doesn't hurt my purpose at all. Gaps can occur with identity, but as long as they are unique (being enforced with an index/constraint), I do not mind at all.
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
March 7, 2014 at 4:19 am
I agree with you Koen.. it depends on your requirement and interest.
🙂
March 7, 2014 at 4:25 am
Sushil Dwivedi (3/7/2014)
If you inserting value into table and your transaction got failed,identity assigned value to failed transaction as welllike
1,2,3,4...failed... than it will not start from 5.. it will start from 6 when you will start insert again.
These limitation we don't have in Sequence.it will have start value,increment and end value
Sequence has gaps too, once a sequence value has been selected from the sequence (for an insert or other usage), it's not reused. It behaves much the same as identity in that regard, plus there's larger gaps possible if the number of cached values is larger
CREATE SEQUENCE Test AS int start with 1 increment BY 1;
CREATE TABLE t1 (
id int,
SomeArbColumn int
)
INSERT INTO t1 (id, SomeArbColumn)-- inserts 1
VALUES (NEXT VALUE FOR Test, 1)
INSERT INTO t1 (id, SomeArbColumn)-- inserts 2
VALUES (NEXT VALUE FOR Test, 1)
INSERT INTO t1 (id, SomeArbColumn)-- inserts 3
VALUES (NEXT VALUE FOR Test, 1)
INSERT INTO t1 (id, SomeArbColumn)-- inserts 4
VALUES (NEXT VALUE FOR Test, 1)
INSERT INTO t1 (id, SomeArbColumn)-- inserts 5, but this will fail
VALUES (NEXT VALUE FOR Test, 1/0)
INSERT INTO t1 (id, SomeArbColumn)-- inserts 6, not 5
VALUES (NEXT VALUE FOR Test, 1)
SELECT * FROM t1
Performance :-
Tests with just three or four concurrent requests (used as a default and manually fetching values), they are faster than an identity column with default caching, and (unlike identity based columns) you have control over the caching, so you can tune to a higher number of pre-calculated values
Link? Or code to reproduce?
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
March 7, 2014 at 4:37 am
GilaMonster (3/7/2014)
Sushil Dwivedi (3/7/2014)
If you inserting value into table and your transaction got failed,identity assigned value to failed transaction as welllike
1,2,3,4...failed... than it will not start from 5.. it will start from 6 when you will start insert again.
These limitation we don't have in Sequence.it will have start value,increment and end value
...
Performance :-
Tests with just three or four concurrent requests (used as a default and manually fetching values), they are faster than an identity column with default caching, and (unlike identity based columns) you have control over the caching, so you can tune to a higher number of pre-calculated values
Link? Or code to reproduce?
Denny Lee has written on the subject:
Microsoft SQL Server: The Sequencing Solution
Although I guess you already knew this. 🙂
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
March 7, 2014 at 4:45 am
Koen Verbeeck (3/7/2014)
Denny Lee has written on the subject:Microsoft SQL Server: The Sequencing Solution
Although I guess you already knew this. 🙂
Denny Cherry?
No performance comparisons there though.
I'd be interested to see some reproducible performance tests that show sequence is faster overall than identity under multiple concurrent usage, mostly because in 2012 they use the same code behind the scenes (which is why identity has those 1000 value gaps on restart)
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
March 7, 2014 at 4:49 am
GilaMonster (3/7/2014)
Koen Verbeeck (3/7/2014)
Denny Lee has written on the subject:Microsoft SQL Server: The Sequencing Solution
Although I guess you already knew this. 🙂
Denny Cherry?
No performance comparisons there though.
I'd be interested to see some reproducible performance tests that show sequence is faster overall than identity under multiple concurrent usage, mostly because in 2012 they use the same code behind the scenes (which is why identity has those 1000 value gaps on restart)
Whoops, wrong Denny 😀
With the IDENTITY property, SQL Server maintains a cache of 20 values in memory, which you can’t adjust. The performance problem with the IDENTITY property is that each time you insert a new row into the table and the IDENTITY property issues a value, the fact that this value has been used is written to the SQL Server database. The faster the rows are loaded into the table, the faster SQL Server must write this metadata to the database.
Unlike the IDENTITY property, a sequence only writes to the database’s metadata that the values were issued when they are first put into the cache. For example, if a sequence issued rows in batches of 1,000, when the first batch is issued the value of 1,000 is written to the metadata. When the value of 1,001 is needed, another 1,000 values are loaded into the cache and the value of 2,000 is written to the metadata. This greatly reduces the number of metadata writes and can improve database performance.
Maybe the information is outdated?
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
March 7, 2014 at 4:55 am
Koen Verbeeck (3/7/2014)
Maybe the information is outdated?
"No performance comparisons", as in hard numbers. Yes, I could run some myself, right now it's not something I can be bothered with. More curious and a knee-jerk reaction when I see 'x is faster than y' statements.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 15 posts - 1 through 15 (of 20 total)
You must be logged in to reply to this topic. Login to reply