question about oracle and specifying primary keys....

laFiera

Senior member
May 12, 2001
862
0
0
CREATE TABLE customer
(custid NUMBER(5) CONSTRAINT customer_custid_pk PRIMARY KEY,
last VARCHAR2(30) CONSTRAINT customer_last_nn NOT NULL,
first VARCHAR2(30));

what's the difference in specifying the primary key as above or just saying????

CREATE TABLE customer
(custid NUMBER(5) not null unique,
last VARCHAR2(30) CONSTRAINT customer_last_nn NOT NULL,
first VARCHAR2(30),
primary (custid);
 

manly

Lifer
Jan 25, 2000
13,591
4,240
136
The only real difference is that in the first case, you named the primary key constraint, which Oracle recommends.

A primary key constraint implies not null and unique, so in the second case, those constraints are redundant.

I'm not an SQL expert, but I think giving a simple constraint such as not null a formal name is unnecessary.