0

This question already has an answer here:

I am starting to use SSMS to manage a database and I am having a problem I would appreciate some help with.

I have a table that was created with

CREATE TABLE [dbo].[Machine](
        [Machine_id] [int] IDENTITY(1,1) NOT NULL,
        [Machine_alias] [nvarchar](50) NULL,
        [Machine_ip] [nvarchar](50) NULL,
        [Machine_stockWarning] [int] NOT NULL,
    .....
CONSTRAINT [PK_machine] PRIMARY KEY CLUSTERED 
(
    [Machine_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

Then I tried to add a row manually and the Machine_id became 1, but there was something wrong with this line so I deleted it. Then I tried to add another row, but this time Machine_id is 2. How can I reinitiate the count so that it starts on 1 again?

marked as duplicate by Max Vernon sql-server Jun 4 at 15:45

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Truncate table dbo.Machine will also reset the seed value to the original specification – Trubs Jun 5 at 4:30
1
DBCC CHECKIDENT('tablename',reseed,1)
  • Thanks. I suppose, GO after this? – KansaiRobot Jun 4 at 5:47
  • Thank you it worked. Just a comment, since I wanted the new id to be 1 I had to do the above operation with reseed,0. – KansaiRobot Jun 4 at 5:54
  • 2
    GO is a batch separator and used by client application, not SQL Server itself. – vonPryz Jun 4 at 5:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.