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 varchar(255),
Address varchar(255),
City varchar(255)
);
Thanks
1 Reply
Sort By
- Arshad440Copper 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'
orYou 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