Generally we have to set a primary key on single column in a table, but if we have need to create more than one columns as primary key then we can use the following SQL Statement,
1- when table is created
CREATE TABLE tblTestDemo(
ID INT NOT NULL,
FirstName VARCHAR(50) NOT NULL,
LastName VARCHAR(50) NOT NULL,
Address VARCHAR(100),
PRIMARY KEY(ID, FirstName)
);
2- If there is no column is set as primary key in created table and we have need to set two or more columns set as primary key then use the following SQL Statement.
ALTER TABLE tblTestDemo
ADD PRIMARY KEY(ID, FirstName);
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Set multiple columns as Primary Key in a table :
Generally we have to set a primary key on single column in a table, but if we have need to create more than one columns as primary key then we can use the following SQL Statement,
1- when table is created
2- If there is no column is set as primary key in created table and we have need to set two or more columns set as primary key then use the following SQL Statement.