PostgreSQL_CE
PGCES-02 · Question #123
You want to set a constraint so that the "item_id" in the "sales" table will always have a value that already exists as "id" in the "item_master" table. Select the correct SQL statement to fill in…
The correct answer is B. FOREIGN KEY (item_id) REFERENCES item_master (id). See the full explanation below for the reasoning.
Question
You want to set a constraint so that the "item_id" in the "sales" table will always have a value that already exists as "id" in the "item_master" table. Select the correct SQL statement to fill in the underlined blank of the "sales" table. Definitions:
CREATE TABLE item_master ( id INTEGER PRIMARY KEY, name TEXT ); CREATE TABLE sales ( sales_id INTEGER, item_id INTEGER, num INTEGER, ); PostgreSQL CE PGCES-02 Exam
Options
- AFOREIGN KEY (id) REFERENCESitem_master (item_id)
- BFOREIGN KEY (item_id) REFERENCES item_master (id)
- CREFERENCESitem_master (item_id)
- DREFERENCESitem_master (id)
- EREFERENCESitem_master (id) TO item_id
How the community answered
(39 responses)- A5% (2)
- B77% (30)
- C3% (1)
- D13% (5)
- E3% (1)
Community Discussion
No community discussion yet for this question.