Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

PostgreSQL Exam PGCES-02 Topic 4 Question 54 Discussion

Actual exam question for PostgreSQL's PGCES-02 exam
Question #: 54
Topic #: 4
[All PGCES-02 Questions]

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, );

Show Suggested Answer Hide Answer
Suggested Answer: A, E

Contribute your Thoughts:

Millie
12 days ago
I bet the correct answer is 'ALTER TABLE sales ADD CONSTRAINT item_id_fkey FOREIGN KEY (item_id) REFERENCES item_master(id)'. I mean, who doesn't love a little extra SQL syntax to spice things up?
upvoted 0 times
...
Ahmad
16 days ago
I wonder if the exam writer is a secret comedian. 'FOREIGN KEY (id) REFERENCES item_master (item_id)' - that's like trying to reference the moon by its serial number!
upvoted 0 times
...
Darell
21 days ago
Ah, the joys of database design! I'm going to have to think this one through carefully. Maybe I'll just ask the database gods for a little guidance.
upvoted 0 times
Trevor
1 days ago
I think the correct SQL statement is B) FOREIGN KEY (item_id) REFERENCES item_master (id)
upvoted 0 times
...
...
Tonette
25 days ago
I'll go with D. It just makes sense to reference the primary key of the 'item_master' table, right? That way, we can ensure the integrity of the data.
upvoted 0 times
...
Sharee
27 days ago
Hmm, I'm not sure. It's been a while since I've dealt with SQL constraints. Maybe I should brush up on my database fundamentals before taking this exam.
upvoted 0 times
Rory
18 days ago
User1: I think the correct SQL statement is B) FOREIGN KEY (item_id) REFERENCES item_master (id)
upvoted 0 times
...
...
Dallas
1 months ago
I think the answer is B. The 'item_id' in the 'sales' table should reference the 'id' column in the 'item_master' table, not the other way around.
upvoted 0 times
Chau
18 days ago
Thanks for confirming! It's important to set up the foreign key relationship correctly for data integrity.
upvoted 0 times
...
Lashaunda
22 days ago
That's correct! The foreign key in the 'sales' table should reference the 'id' column in the 'item_master' table.
upvoted 0 times
...
Felix
27 days ago
B) FOREIGN KEY (item_id) REFERENCES item_master (id)
upvoted 0 times
...
...
Justine
2 months ago
I'm not sure about the answer. Can someone explain why option B is the correct one?
upvoted 0 times
...
Evangelina
2 months ago
I agree with Earlean. Using FOREIGN KEY (item_id) REFERENCES item_master (id) ensures that the 'item_id' in 'sales' table will always have a value that exists in the 'id' column of 'item_master' table.
upvoted 0 times
...
Earlean
2 months ago
I think the correct answer is B) FOREIGN KEY (item_id) REFERENCES item_master (id). It makes sense to reference the 'id' column in 'item_master' table.
upvoted 0 times
...

Save Cancel