How to add composite primary key to table

Domnic picture Domnic · Aug 29, 2009 · Viewed 148.3k times · Source
create table d(id numeric(1), code varchar(2))

After I create the above table how can I add a composite primary key on both fields and also a foreign key?

Answer

Simon Nickerson picture Simon Nickerson · Aug 29, 2009

In Oracle, you could do this:

create table D (
  ID numeric(1),
  CODE varchar(2),
  constraint PK_D primary key (ID, CODE)
);