Which CREATE TABLE statement is valid?
A.
CREATE TABLE ord_details
(ord_no NUMBER(2) PRIMARY KEY,
item_no NUMBER(3) PRIMARY KEY,
ord_date date NOT NULL);
B.
CREATE TABLE ord_details
(ord_no NUMBER(2) UNIQUE, NOT NULL,
item_no NUMBER(3),
ord_date date DEFAULT SYSDATE NOT NULL);
C.
CREATE TABLE ord_details
(ord_no NUMBER(2) ,
item_no NUMBER(3),
ord_date date DEFAULT NOT NULL,
CONSTRAINT ord_uq UNIQUE (ord_no),
CONSTRAINT ord_pk PRIMARY KEY (ord_no));
D.
CREATE TABLE ord_details
(ord_no NUMBER(2),
item_no NUMBER(3),
ord_date date DEFAULT SYSDATE NOT NULL,
CONSTRAINT ord_pk PRIMARY KEY (ord_no, item_no));
C is incorrect. DEFAULT NOT NULL is not correct.
ALSO,
ORA-02261: such unique or primary key already exists in the table
02261. 00000 – “such unique or primary key already exists in the table”
For B, if:
CREATE TABLE ord_details
(ord_no NUMBER(2) UNIQUE NOT NULL, — no comma —
item_no NUMBER(3),
ord_date date DEFAULT NOT NULL);
then it will be correct.
Correct answer is D