How to use primary key ordered in sql server

Posted by JAYAKUMARS under C# on 2/22/2017 | Points: 10 | Views : 194 | Status : [Member] [MVP] | Replies : 1
Hi

How to Automatically raise this Query after delete

My table primary key with identity(1,1) so when i delete last record after insert my
primary key value not order so i used after delete I execute below query so

i need how to set automatically set when i delete last record after i insert automatically
coming my primary key orderd

DBCC CHECKIDENT ('BOOKS', RESEED, 3)

Mark as Answer if its helpful to you


Responses

Posted by: Bandi on: 2/23/2017 [Member] [MVP] Platinum | Points: 25

Up
0
Down
If you don't want the missing identity values due to DELETEs, can implement the below code whenever delete happens on that table

DECLARE @Max INT;
SET @Max = (SELECT MAX (identity_column_name) FROM table_name);
DBCC CHECKIDENT('table_name', RESEED, @Max);



Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

JAYAKUMARS, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response