how we can use more then one primary key in Single Table

Answers were Sorted based on User's Feedback



how we can use more then one primary key in Single Table..

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

how we can use more then one primary key in Single Table..

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

how we can use more then one primary key in Single Table..

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

how we can use more then one primary key in Single Table..

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

how we can use more then one primary key in Single Table..

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

how we can use more then one primary key in Single Table..

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

how we can use more then one primary key in Single Table..

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

how we can use more then one primary key in Single Table..

Answer / jemi

can't

Is This Answer Correct ?    8 Yes 9 No

how we can use more then one primary key in Single Table..

Answer / sriram

Can't

Is This Answer Correct ?    2 Yes 5 No

Post New Answer

More MySQL Interview Questions

What is select query in mysql?

0 Answers  


Why is the basic difference between left join, right join and inner join?

0 Answers  


How many tables we can create in mysql database?

0 Answers  


Should I use pdo or mysqli?

0 Answers  


What is the data type for file in mysql?

0 Answers  






What is join in mysql? What are the different types of join?

0 Answers  


In mysql, what is the default storage engine?

0 Answers  


How do I copy a table in mysql?

0 Answers  


Which statement is used to delete a table in MySQL.

0 Answers  


if we want to load data from a text file into a mysql table, but the columns in table are 1st: code(int) and 2nd: city(varchar), but in text file the format is 1st cityname and then code separeted by delimeters. how to load?

2 Answers  


What is meant by mysql database?

1 Answers  


I want to insert userid of a customer,order time,etc in a table called ordermaster with orderid as primary key.Same time the product codes and required quantities (a1,2 and a2 4 and so on)inserted in another table orderdetails with same orderid reference.How the code will be in JSP using MySQL?

0 Answers  


Categories