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
- Dozens more answers to tough SQL questions from Rudy Limeback.
- The Best SQL Web Links: tips, tutorials, scripts, and more.
- Have an SQL tip to offer your fellow DBAs and developers? The best tips submitted will receive a cool prize. Submit your tip today!
- Ask your technical SQL questions -- or help out your peers by answering them -- in our live discussion forums.
- Ask the Experts yourself: Our SQL, database design, Oracle, SQL Server, DB2, metadata, object-oriented and data warehousing gurus are waiting to answer your toughest questions.
This was first published in May 2003