Q
Problem solve Get help with specific problems with your technologies, process and projects.

Can a table have two primary keys?

Is it possible to have two primary keys on the same table?

No. A table can have only one primary key.

However, that primary key can consist of two columns. For example, consider this table of DatabaseProducts:

Company    Product     Release
IBM        DB2         5
Microsoft  SQL Server  7.0
Microsoft  Access      97
Oracle     Oracle      8
Sybase     ASE         12.5

As it stands, you could define this table with:

create table DatabaseProducts
 ( Company  varchar(20)
 , Product  varchar(20)
 , Release  varchar(10)
 , constraint DatabaseProductPK
        primary key (Company, Product)
 )

If you wanted the table to contain both Microsoft SQL Server 7.0 and Microsoft SQL Server 2000, then the primary key would have to include the Release column as well.

For More Information


This was last published in May 2003

Dig Deeper on Oracle and SQL

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide.com

SearchDataCenter

SearchContentManagement

SearchHRSoftware

Close