Can't we have two primary keys in a table? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can't we have two primary keys in a table?

22nd May 2018, 4:25 AM
priyatham sagar
3 Answers
+ 3
A Table can have a Composite Primary Key which is a primary key made from two or more columns. For example: CREATE TABLE userdata ( userid INT, userdataid INT, info char(200), primary key (userid, userdataid) ); Source: https://stackoverflow.com/questions/217945/can-i-have-multiple-primary-keys-in-a-single-table?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
22nd May 2018, 4:33 AM
Sachin Artani
Sachin Artani - avatar
+ 2
Primary keys are meant for making each row(or record) of data unique. Having two primary key is useless since one is enough to find data. If you don't have a single primary key you can use multiple fields as combined primary key for identifying a group(row) of data.
22nd May 2018, 4:35 AM
Akib
Akib - avatar
+ 2
thank you guys
22nd May 2018, 4:42 AM
priyatham sagar