how we can use more then one primary key in Single Table
Answers were Sorted based on User's Feedback
Answer / mukesh
Its impossible to create two primary key in a single table
but if we use composite key we have do it just like that
CREATE TABLE Test (id1 INT NOT NULL, id2 INT NOT NULL, name
CHAR(20) NOT NULL, PRIMARY KEY(id1,id2));
| Is This Answer Correct ? | 14 Yes | 0 No |
Answer / sathishrpillai
A single table can't have two primary keys.it can only
forgein keys.but u can use any number of foregin key in a
single table.
| Is This Answer Correct ? | 15 Yes | 7 No |
Answer / piyush
We can use more then one primary keys in a single table but
it is possible only in 2005. otherwise we can not use more
then one primary keys in a single table.
| Is This Answer Correct ? | 10 Yes | 3 No |
Answer / frank
Can't, but can create primary key with multiple columns:
CREATE TABLE Test (id1 INT NOT NULL, id2 INT NOT NULL, name
CHAR(20) NOT NULL, PRIMARY KEY(id1,id2));
| Is This Answer Correct ? | 8 Yes | 1 No |
Answer / sharad
CREATE TABLE Test (id1 INT ,id2 INT , name CHAR(20) NOT
NULL, PRIMARY KEY(id1,id2));
| Is This Answer Correct ? | 4 Yes | 0 No |
Answer / naveen
with this query two primary keys are created but in the insertion time it doesn'y work automatically.it says it can't insert null value in id1.
CREATE TABLE Test (id1 INT NOT NULL, id2 INT NOT NULL, name
CHAR(20) NOT NULL, PRIMARY KEY(id1,id2));
| Is This Answer Correct ? | 3 Yes | 0 No |
Answer / sonu kumar
we can more than one primary key in a single table in case of self joining
eg:-if want to details of employee and their manager in same table than empid,mngid both treated as primary key
| Is This Answer Correct ? | 0 Yes | 0 No |
what is cte? : Mysql dba
What is ISAM?
How do you index just the first four bytes of the column?
What is view in mysql?
How do I truncate all tables in mysql?
Write a query to stop mysql in unix
How do I update a variable in mysql?
How to get last inserted id after insert data from a table in mysql?
What is the data type for image?
Is blocked because of many connection errors unblock with mysqladmin flush hosts?
Can mysql function return a table?
What are the differences between binary and varbinary?
Oracle (3259)
SQL Server (4518)
MS Access (429)
MySQL (1402)
Postgre (483)
Sybase (267)
DB Architecture (141)
DB Administration (291)
DB Development (113)
SQL PLSQL (3330)
MongoDB (502)
IBM Informix (50)
Neo4j (82)
InfluxDB (0)
Apache CouchDB (44)
Firebird (5)
Database Management (1411)
Databases AllOther (288)