+1 vote
77 views
in Database Management Systems by

1 Answer

+1 vote
by
selected by (user.guest)
 
Best answer

A foreign key constraint specifies that the values in a column (or a group of columns) must match the values appearing in some row of another table. We say this maintains the referential integrity between two related tables. Say you have the product table that we have used several times already:  

CREATE TABLE products (product_no integer PRIMARY KEY, name text, price numeric);  

Let's also assume you have a table storing orders of those products. We want to ensure that the orders table only contains orders of products that actually exist. So we define a foreign key constraint in the orders table that references the products table:  

CREATE TABLE orders ( order_id integer PRIMARY KEY,product_no integer REFERENCES products (product_no), quantity integer);  

Now it is impossible to create orders with product_no entries that do not appear in the products table.  

We say that in this situation the orders table is the referencing table and the products table is the referenced table. Similarly, there are referencing and referenced columns.

Related questions

+1 vote
1 answer 88 views
+1 vote
1 answer 80 views
+1 vote
1 answer 194 views
+1 vote
1 answer 184 views
+3 votes
1 answer 355 views
+1 vote
1 answer 72 views
+1 vote
1 answer 613 views
0 votes
1 answer 26 views
0 votes
1 answer 75 views
0 votes
1 answer 75 views
+1 vote
1 answer 94 views
+1 vote
1 answer 120 views
+1 vote
1 answer 162 views
+1 vote
1 answer 201 views
+1 vote
1 answer 94 views
+2 votes
1 answer 419 views
+2 votes
1 answer 509 views
+2 votes
1 answer 764 views
+2 votes
1 answer 383 views
+1 vote
1 answer 500 views
+2 votes
1 answer 485 views
+1 vote
1 answer 590 views
+1 vote
1 answer 331 views
+1 vote
0 answers 16 views
+1 vote
1 answer 34 views
+1 vote
1 answer 36 views
+1 vote
1 answer 36 views
+1 vote
1 answer 48 views
0 votes
1 answer 83 views
+1 vote
1 answer 42 views
0 votes
1 answer 64 views
asked Oct 25 in Database Management Systems by (user.guest)
0 votes
1 answer 83 views
asked Sep 23 in Database Management Systems by (user.guest)
+1 vote
1 answer 71 views
+1 vote
1 answer 74 views
asked Sep 23 in Database Management Systems by anonymous
+1 vote
1 answer 153 views
+1 vote
1 answer 194 views
Welcome to CPENTalk.com
Solution-oriented students of computer engineering on one platform to get you that

ONE SOLUTION

...