SQL > ???? > ???

???? ?? ??(?? ???)? ?? ???? ???? ?????.???? ??? ???? ?? ??? (referential integrity) ? ????????.????? ??? ??? ??? ???????? ???? ????.

?? ?? ??? ??? ???: ??? CUSTOMER ???? ?? ???? ???? ???? ??, ?? ??? ORDERS ????? ?? ???? ??? ???? ???? ????. ???? ?? ?? ??? ?? ???? ??? CUSTOMER ???? ???? ??? ??? ????. ??? ??? ORDERS ??? ???? ???? ? ???? CUSTOMER ???? ???? ???? ????. ???? ??? ?? ORDERS ???? ???CUSTOMER ???? ??????? ???? ????. ????? ORDERS ?????, ??? CUSTOMER ???? ?????? ???? ??? ????.

? ? ??? ??? ??? ??????:

CUSTOMER ??
??? ??
SID ???
Last_Name  
First_Name  

ORDERS ??
??? ??
Order_ID ???
Order_Date  
Customer_SID ???
Amount  

?? ??? ORDERS ???? Customer_SID ?? ??? CUSTOMER ????SID ??? ???? ?????.

?? ??? ORDERS ??? ??? ???? ???? ??? ?????:

MySQL:

CREATE TABLE ORDERS
(Order_ID integer,
Order_Date date,
Customer_SID integer,
Amount double,
PRIMARY KEY (Order_ID),
FOREIGN KEY (Customer_SID) REFERENCES CUSTOMER (SID));

Oracle:

CREATE TABLE ORDERS
(Order_ID integer PRIMARY KEY,
Order_Date date,
Customer_SID integer REFERENCES CUSTOMER (SID),
Amount double);

SQL Server:

CREATE TABLE ORDERS
(Order_ID integer PRIMARY KEY,
Order_Date datetime,
Customer_SID integer REFERENCES CUSTOMER (SID),
Amount double);

?? ?? ?? ??? ??????? ???? ?????. ??? ORDERS ??? ?? ??? ?? ???? ???? ????? ?????:

MySQL:

ALTER TABLE ORDERS
ADD FOREIGN KEY (Customer_SID) REFERENCES CUSTOMER (SID);

Oracle:

ALTER TABLE ORDERS
ADD (CONSTRAINT fk_orders1) FOREIGN KEY (Customer_SID) REFERENCES CUSTOMER (SID);

SQL Server:

ALTER TABLE ORDERS
ADD FOREIGN KEY (Customer_SID) REFERENCES CUSTOMER (SID);

SQL DROP TABLE >>
?


Copyright © 2021   1keydata.com   All Rights Reserved