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 PGCES-02 Exam - Topic 4 Question 54 Discussion

Posted by Marge on Jan 23, 2024 at 05:09 PM

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

Suggested Answer: A, E

Get Premium PGCES-02 Questions as Interactive Web-Based Practice Test or PDF Real Exam Format Detailed Explanations Instant Access Get Your Practice Test
39 comments · newest first
CO
Corinne 10 months ago
Surprised that E is so misleading!
PH
Phyliss 11 months ago
I thought it was C at first, but B is right.
HA
Hailey 11 months ago
Wait, why is A even an option?
CA
Casie 11 months ago
Totally agree, B makes sense.
VI
Vicky 11 months ago
B is the correct choice!
RH
Rhea 12 months ago
I definitely remember that the foreign key needs to reference the primary key, so I think B is the right choice since it links "item_id" to "id".
RE
Reena 12 months ago
I'm a bit confused about the syntax here. I feel like it could be either B or D, but I can't recall the exact details.
RE
Reena 12 months ago
I remember practicing a similar question, and I think the correct answer is B because it matches the "item_id" in sales to the "id" in item_master.
LO
Lorrine 1 year ago
I think the foreign key should reference the "id" in the "item_master" table, but I'm not sure which option that is.
MI
Mitzie 1 year ago
I'm pretty confident about this one. The "item_id" in the "sales" table needs to be a foreign key that references the "id" column in the "item_master" table, so the correct answer is option B.
LA
Lashaunda 1 year ago
This is a straightforward foreign key constraint question. The "item_id" in the "sales" table needs to reference the "id" column in the "item_master" table, so the correct answer is option B.
JA
Jacqueline 1 year ago
Okay, I think I've got this. The key is to match the "item_id" column in the "sales" table to the "id" column in the "item_master" table. So the correct answer is option B.
GL
Glen 1 year ago
Hmm, this looks like a tricky one. I'll need to carefully read through the table definitions and think about the relationship between the two tables.
SH
Shalon 1 year ago
I'm a bit confused here. The question is asking about setting a constraint, but the options seem to be about referencing columns. I'll need to double-check my understanding of foreign keys and referential integrity.
TA
Tandra 1 year ago
I'm pretty confident this is an A. Deduplicating the data is the best way to ensure no one gets the same email twice.
LI
Ligia 1 year ago
Okay, let's see. A digital network should provide secure data transport, so I'm leaning towards option C. But I'll double-check the other options just to be sure.
MY
Myra 1 year ago
I think since the maximum is set to 8, the system might just remain at 8, but I can't recall if it adds beyond that.
MI
Millie 1 year 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?
AH
Ahmad 1 year 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!
TH
Thora 1 year ago
↳ replying to Ahmad
Haha, yeah, that would be like referencing the moon by its serial number!
CR
Crissy 1 year ago
↳ replying to Ahmad
E) REFERENCES item_master (id) TO item_id
KA
Kanisha 1 year ago
↳ replying to Ahmad
That's the correct SQL statement to set the constraint.
JO
Josphine 1 year ago
↳ replying to Ahmad
B) FOREIGN KEY (item_id) REFERENCES item_master (id)
DA
Darell 1 year 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.
JA
Jamie 1 year ago
↳ replying to Darell
Yes, that way we ensure that the 'item_id' in 'sales' always matches an existing 'id' in 'item_master'.
TE
Tegan 1 year ago
↳ replying to Darell
That makes sense, we want to reference the 'id' column in 'item_master' from the 'item_id' column in 'sales'.
TR
Trevor 1 year ago
↳ replying to Darell
I think the correct SQL statement is B) FOREIGN KEY (item_id) REFERENCES item_master (id)
TO
Tonette 1 year 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.
SH
Sharee 1 year 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.
LU
Lucina 1 year ago
↳ replying to Sharee
User1: Definitely, it helps maintain data integrity in the database.
VI
Vivienne 1 year ago
↳ replying to Sharee
User2: That makes sense. It's important to have the foreign key reference the primary key in the other table.
RO
Rory 1 year ago
↳ replying to Sharee
User1: I think the correct SQL statement is B) FOREIGN KEY (item_id) REFERENCES item_master (id)
DA
Dallas 1 year 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.
CH
Chau 1 year ago
↳ replying to Dallas
Thanks for confirming! It's important to set up the foreign key relationship correctly for data integrity.
LA
Lashaunda 1 year ago
↳ replying to Dallas
That's correct! The foreign key in the 'sales' table should reference the 'id' column in the 'item_master' table.
FE
Felix 1 year ago
↳ replying to Dallas
B) FOREIGN KEY (item_id) REFERENCES item_master (id)
JU
Justine 1 year ago
I'm not sure about the answer. Can someone explain why option B is the correct one?
EV
Evangelina 2 years 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.
EA
Earlean 2 years 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.
0/2000 characters

Save Cancel