0

foreign key syntax

what's the syntax to use foreign key in sql?

6th Dec 2016, 7:26 AM
Himas Adin Nugroho
Himas Adin Nugroho - avatar
2 odpowiedzi
0
A FOREIGN KEY in one table points to a PRIMARY KEY in another table. CUSTOMERS table: CREATE TABLE CUSTOMERS( ID INT NOT NULL, NAME VARCHAR (20) NOT NULL, AGE INT NOT NULL, ADDRESS CHAR (25) , SALARY DECIMAL (18, 2), PRIMARY KEY (ID) ); ORDERS table: CREATE TABLE ORDERS ( ID INT NOT NULL, DATE DATETIME, CUSTOMER_ID INT references CUSTOMERS(ID), AMOUNT double, PRIMARY KEY (ID) ); ALTER TABLE ORDERS ADD FOREIGN KEY (Customer_ID) REFERENCES CUSTOMERS (ID);
6th Dec 2016, 10:11 AM
Akwin Lopez
Akwin Lopez - avatar
0
thankss ^^ my professor doesn't explain it in detail.. that's why i still confused. thanks a lot for your answer. it's really helpful ^^
9th Dec 2016, 5:58 AM
Himas Adin Nugroho
Himas Adin Nugroho - avatar