Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Alter a table for Identity Specification is identity SQL Server


not working

ALTER TABLE ProductInProduct ALTER COLUMN Id KEY IDENTITY (1, 1);

Check Image

I have a table ProductInProduct is want its id should be Unique.. enter image description here

like image 316
smart boy Avatar asked Jun 25 '13 07:06

smart boy


2 Answers

You don't set value to default in a table. You should clear the option "Default value or Binding" first.

like image 102
maino Avatar answered Sep 28 '22 18:09

maino


You cannot "convert" an existing column into an IDENTITY column - you will have to create a new column as INT IDENTITY:

ALTER TABLE ProductInProduct 
ADD NewId INT IDENTITY (1, 1);

Update:

OK, so there is a way of converting an existing column to IDENTITY. If you absolutely need this - check out this response by Martin Smith with all the gory details.

like image 21
marc_s Avatar answered Sep 28 '22 18:09

marc_s