Home > Ask the Oracle Experts > SQL Questions & Answers > Can a table have two primary keys?
Ask The Oracle Expert: Questions & Answers
EMAIL THIS

Can a table have two primary keys?

Rudy Limeback EXPERT RESPONSE FROM: Rudy Limeback

Pose a Question
Other Oracle Categories
Meet all Oracle Experts
Become an Expert for this site


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


>
QUESTION POSED ON: 30 May 2003
Is it possible to have two primary keys on the same table?

>
EXPERT RESPONSE

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


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


RELATED CONTENT
SQL
SQL to select rows 1000 through 3000 in a table
SQL query to combine rows
The SQL REPLACE function
CASE expressions in the ORDER BY clause
Finding a column value inside a user-supplied string
Update a specific column in a field or row?
Using BETWEEN with DATETIMEs in SQL
Which normal form is used most?
IN list or series of OR conditions?
Connecting tables in a database

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice

HomeNewsTopicsTipsAsk the ExpertsMultimediaWhite PapersProductsBlogs
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 2003 - 2008, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts