How do you rebuild an identity column?



How do you rebuild an identity column?..

Answer / Indramani Sharma

"To rebuild an identity column in SQL Server, you can use the DBCC CHECKIDENT command followed by SET NOCOUNT ON and then SET IDENTITY_INSERT [table_name] ON. Here's an example:

```sql
SET NOCOUNT ON;
DBCC CHECKIDENT ('[table_name]', RESEED, 0);
SET IDENTITY_INSERT [table_name] ON;
UPDATE [table_name] SET [identity_column] = identity([identity_column]);
SET IDENTITY_INSERT [table_name] OFF;
```
This will reset the identity column to start from 1.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More SQL Server Interview Questions

What is the system function to get the current user's user id?

2 Answers   HCL,


what command is used to create a table by copying the structure of another table?

7 Answers  


Can primary key be a foreign key?

1 Answers  


Explain database normalization?

1 Answers  


How do I setup a local sql server database?

1 Answers  


What is difference in performance between insert top (n) into table and using top with insert?

1 Answers  


How to get the query of a table in sql server?

1 Answers  


what is a major difference between sql server 6.5 and 7.0 platform wise? : Sql server database administration

1 Answers  


How do we return a record set from a Stored Procedure in SQl server 2000?

3 Answers  


WHAT OPERATOR PERFORMS PATTERN MATCHING?

2 Answers   CarrizalSoft Technologies, CTS,


What are the requirements for sql server 2016?

1 Answers  


can you any body tell me why are go for the rebuild the master database.what is the reason?

2 Answers  


Categories