SQL FOREIGN KEY Constraint
SQL FOREIGN KEY Constraint
Foreign key - 테이블 간의 관계를 생성한다.
child table - foreign key 있는 테이블
parent table - primary key 있는 테이블
SQL FOREIGN KEY on CREATE TABLE
CREATE TABLE Orders (
OrderID int NOT NULL,
OrderNumber int NOT NULL,
PersonID int,
PRIMARY KEY (OrderID),
FOREIGN KEY (PersonID) REFERENCES Persons(PersonID)
);
SQL FOREIGN KEY on ALTER TABLE
ALTER TABLE Orders
ADD FOREIGN KEY (PersonID) REFERENCES Persons(PersonID);
DROP a FOREIGN KEY Constraint
ALTER TABLE Orders
DROP FOREIGN KEY FK_PersonOrder;
'Computer Science > Database' 카테고리의 다른 글
W3Schools SQL | #49 SQL DEFAULT CONSTRAINT 이용법 (0) | 2022.10.30 |
---|---|
W3Schools SQL | #48 SQL CHECK CONSTRAINT (0) | 2022.10.30 |
W3Schools SQL | #46 SQL PRIMARY KEY CONSTRAINT 이용법 (0) | 2022.10.30 |
W3Schools SQL | #44 SQL NOT NULL CONSTRAINT 제약 조건 (0) | 2022.10.29 |
W3Schools SQL | #43 SQL CONSTRAINT 제약 조건 (0) | 2022.10.29 |