Forum Discussion
elitesmitpatel
Aug 16, 2024Copper Contributor
update a created column to a primary key column
I have created a table mentioned below, now i want to convert "PersonID" into Primary key . Please provide me the code? create table Persons( PersonID int, LastName varchar(255), FirstName varcha...
Arshad440
Aug 16, 2024Brass Contributor
Hi,
You Should Open object Explorer in SSMS and Find your table and expand the table where you can see the columns of your table,
Right Click the Column you want and click 'Set Primary Key'
or
You should use this Query
ALTER TABLE Persons
ALTER COLUMN PersonID INT NOT NULL;
ALTER TABLE Persons
ADD CONSTRAINT PK_Employees PRIMARY KEY (PersonID);
regards
Arshad