Primary key
Can a primary key contains more than one column?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Arjun PanwarPosted Nov 29, 2011, 12:57 AM
Example:
CREATE TABLE Persons
(
P_Id int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255),
City varchar(255),
CONSTRAINT pk_PersonID PRIMARY KEY (P_Id,LastName)
)
Note: In the example above there is only ONE PRIMARY KEY (pk_PersonID). However, the value of the pk_PersonID is made up of two columns (P_Id and LastName).
Akash AhlawatPosted Nov 29, 2011, 4:23 AM
Pravin MorePosted Nov 29, 2011, 12:42 AM
Hi Akash,
You can only have one primary key, but you can have multiple columns in your primary key.
CREATE TABLE userdata
( userid integer,
userdataid integer,
info char(200)
primary key (userid, userdataid)
);
Thanks,
Pravin
Priya LingePosted Nov 29, 2011, 12:34 AM
1.NO, A table can have Only One primary key.
2.But a table can have any number of composite primary key's
3. A primary key can have more than one column.it is called Composite Primary Key.
4.The primary key is one of the unique keys defined on a table, but is selected to be the key of first importance.
There can be only one primary key on a table.
5.Composite key: a primary key containing more than one column .
6.we can create composite primary key upto 16 columns only.
Please check below link for more information.
http://publib.boulder.ibm.com/infocenter/db2luw/v8/index.jsp?topic=/com.ibm.db2.udb.doc/admin/c0004799.htmHope this will help you.
Thanks.