Which statement is true regarding the execution of the above SQL commands?

Examine the following SQL commands:
SQL>CREATE TABLE products (
prod_id NUMBER(3) CONSTRAINT p_ck CHECK (prod_id > 0),
prod_name CHAR(30),
prod_qty NUMBER(6),
CONSTRAINT p_name NOT NULL,
CONSTRAINT prod_pk PRIMARY KEY (prod_id));
SQL>CREATE TABLE warehouse (
warehouse_id NUMBER(4),
roomno NUMBER(10) CONSTRAINT r_id CHECK(roomno BETWEEN 101 AND 200),
location VARCHAR2(25),
prod_id NUMBER(3),
CONSTRAINT wr_pr_pk PRIMARY KEY (warehouse_id,prod_id),
CONSTRAINT prod_fk FOREIGN KEY (prod_id) REFERENCES products(prod_id));
Which statement is true regarding the execution of the above SQL commands?

Examine the following SQL commands:
SQL>CREATE TABLE products (
prod_id NUMBER(3) CONSTRAINT p_ck CHECK (prod_id > 0),
prod_name CHAR(30),
prod_qty NUMBER(6),
CONSTRAINT p_name NOT NULL,
CONSTRAINT prod_pk PRIMARY KEY (prod_id));
SQL>CREATE TABLE warehouse (
warehouse_id NUMBER(4),
roomno NUMBER(10) CONSTRAINT r_id CHECK(roomno BETWEEN 101 AND 200),
location VARCHAR2(25),
prod_id NUMBER(3),
CONSTRAINT wr_pr_pk PRIMARY KEY (warehouse_id,prod_id),
CONSTRAINT prod_fk FOREIGN KEY (prod_id) REFERENCES products(prod_id));
Which statement is true regarding the execution of the above SQL commands?

A.
Both commands execute successfully.

B.
The first CREATE TABLE command generates an error because the NULL constraint is not valid.

C.
The second CREATE TABLE command generates an error because the CHECK constraint is not valid.

D.
The first CREATE TABLE command generates an error because CHECK and PRIMARY KEY constraints cannot be used for the same column.

E.
The first CREATE TABLE command generates an error because the column PROD_ID cannot be used in the PRIMARY KEY and FOREIGN KEY constraints.



Leave a Reply 4

Your email address will not be published. Required fields are marked *


Ritam Tiwari

Ritam Tiwari

option b:

why the NULL constraint used there is INVALID?????

Justyna

Justyna

Because you cannot define NOT NULL as other constraints. You do that in the following way:
prod_qty NUMBER(6) NOT NULL,

Ritam Tiwari

Ritam Tiwari

thanks …correct

Ritam Tiwari

Ritam Tiwari

YES…”NOT NULL” CONSTRAINT CAN ONLY BE USED AS COLUMN LEVEL CONSTRAINT NOT AS TABLE LEVEL CONSTRAINT.