A foreign key is a field (or fields) that points to the primary key of another table. The purpose of the foreign key is to ensure referential integrity of the data. In other words, only values that are supposed to appear in the database are permitted.
Table CUSTOMER
Table ORDERS
Script :
CREATE TABLE ORDERS
(Order_ID integer primary key,
Order_Date datetime,
Customer_SID integer references CUSTOMER(SID),
Amount double);
if you alter the reference:
ALTER TABLE ORDERS
ADD FOREIGN KEY (customer_sid) REFERENCES CUSTOMER(SID);
Table CUSTOMER
| column name | characteristic |
| SID | Primary Key |
| Last_Name | |
| First_Name |
Table ORDERS
| column name | characteristic |
| Order_ID | Primary Key |
| Order_Date | |
| Customer_SID | Foreign Key |
| Amount |
Script :
CREATE TABLE ORDERS
(Order_ID integer primary key,
Order_Date datetime,
Customer_SID integer references CUSTOMER(SID),
Amount double);
if you alter the reference:
ALTER TABLE ORDERS
ADD FOREIGN KEY (customer_sid) REFERENCES CUSTOMER(SID);
No comments:
Post a Comment