Quantcast
Channel: Reset identity seed after deleting records in SQL Server - Stack Overflow
Browsing all 26 articles
Browse latest View live

Answer by abolfazl sadeghi for Reset identity seed after deleting records in...

you can CHECKIDENT To Reset SeedDBCC CHECKIDENT ( table_name [ , { NORESEED | { RESEED [ , new_reseed_value ] } } ])[ WITH NO_INFOMSGS ]Example DBCC CHECKIDENT ('TAble', reseed,0)--Example QueryYou can...

View Article



Answer by R.Alonso for Reset identity seed after deleting records in SQL Server

Use this sp for all tables:reseed 'youtable'after delete a record (in a trigger p.e.)or when you needit.CREATE procedure RESEED(@Tabla nvarchar(100)) as declare @CampoIdentidad nvarchar(100) SELECT...

View Article

Answer by Abolfazl for Reset identity seed after deleting records in SQL Server

Hello this stored procedure DELETE ALL ROWS of a table and check whether has identity column in the table ,it will be reseed .**** CAUTION : ALL ROWS WILL BE DELETED . *****Create PROCEDURE...

View Article

Answer by deroby for Reset identity seed after deleting records in SQL Server

It seems like the majority of replies here assumes that the table is empty and the Identity value needs to be reset.However, how I read the question is that @xorpower now has a table with records 1, 2,...

View Article

Answer by Trent for Reset identity seed after deleting records in SQL Server

I have just used DBCC CHECKIDENT successfullyThings to note:when referencing table name square brackets are not acceptedDBCC CHECKIDENT('TableName',RESEED,n) will reset back to n+1e.g. DBCC...

View Article


Answer by KimvdLinde for Reset identity seed after deleting records in SQL...

I've been trying to get this done for a large number of tables during development, and this works as a charm.DBCC CHECKIDENT('www.newsType', RESEED, 1);DBCC CHECKIDENT('www.newsType', RESEED);So, you...

View Article

Answer by Ali Sufyan for Reset identity seed after deleting records in SQL...

Reseeding to 0 is not very practical unless you are cleaning up the table as a whole.other wise the answer given by Anthony Raymond is perfect. Get the max of identity column first, then seed it with max.

View Article

Answer by Chris Mack for Reset identity seed after deleting records in SQL...

I use the following script to do this. There's only one scenario in which it will produce an "error", which is if you have deleted all rows from the table, and IDENT_CURRENT is currently set to 1, i.e....

View Article


Answer by Fandango68 for Reset identity seed after deleting records in SQL...

For a complete DELETE rows and reset the IDENTITY count, I use this (SQL Server 2008 R2)USE mydb--...

View Article


Answer by boggy for Reset identity seed after deleting records in SQL Server

Use this stored procedure:IF (object_id('[dbo].[pResetIdentityField]') IS NULL) BEGIN EXEC('CREATE PROCEDURE [dbo].[pResetIdentityField] AS SELECT 1 FROM DUMMY'); ENDGOSET ANSI_NULLS ONGOSET...

View Article

Answer by Pratik Patel for Reset identity seed after deleting records in SQL...

First : Identity Specification Just : "No">> Save Database Execute ProjectAfter then : Identity Specification Just : "YES">> Save Database Execute ProjectYour Database ID, PK Start from 1...

View Article

Answer by Dyna Dave for Reset identity seed after deleting records in SQL Server

Truncate table is preferred because it clears the records, resets the counter and reclaims the disk space. Delete and CheckIdent should be used only where foreign keys prevent you from truncating.

View Article

Answer by Mukesh Pandey for Reset identity seed after deleting records in SQL...

Reset identity column with new id...DECLARE @MAX INTSELECT @MAX=ISNULL(MAX(Id),0) FROM [TestTable]DBCC CHECKIDENT ('[TestTable]', RESEED,@MAX)

View Article


Answer by epic for Reset identity seed after deleting records in SQL Server

@jacobDBCC CHECKIDENT ('[TestTable]', RESEED,0)DBCC CHECKIDENT ('[TestTable]', RESEED)Worked for me, I just had to clear all entries first from the table, then added the above in a trigger point after...

View Article

Answer by jacob for Reset identity seed after deleting records in SQL Server

issuing 2 command can do the trickDBCC CHECKIDENT ('[TestTable]', RESEED,0)DBCC CHECKIDENT ('[TestTable]', RESEED)the first reset the identity to zero , and the next will set it to the next available...

View Article


Answer by Atal Kishore for Reset identity seed after deleting records in SQL...

Although most answers are suggesting RESEED to 0, many times we need to just reseed to next Id availabledeclare @max intselect @max=max([Id]) from [TestTable]if @max IS NULL --check when max is...

View Article

Answer by Bimzee for Reset identity seed after deleting records in SQL Server

DBCC CHECKIDENT (<TableName>, reseed, 0)This will set the current identity value to 0.On inserting the next value, the identity value get incremented to 1.

View Article


Answer by Abdul Hannan Ijaz for Reset identity seed after deleting records in...

Its always better to use TRUNCATE when possible instead of deleting all records as it doesn't use log space also.In case we need delete and need to reset the seed, always remember that if table was...

View Article

Answer by RealSollyM for Reset identity seed after deleting records in SQL...

Although most answers are suggesting RESEED to 0, and while some see this as a flaw for TRUNCATED tables, Microsoft has a solution that excludes the IDDBCC CHECKIDENT ('[TestTable]', RESEED)This will...

View Article

Answer by Solomon Rutzky for Reset identity seed after deleting records in...

It should be noted that IF all of the data is being removed from the table via the DELETE (i.e. no WHERE clause), then as long as a) permissions allow for it, and b) there are no FKs referencing the...

View Article
Browsing all 26 articles
Browse latest View live


Latest Images