1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
CREATE TABLE COUNTRY –국가 ( Country_Code char(2) NOT NULL , –국가코드 Country_Name varchar(50) NOT NULL default ” –국가명 ) go ALTER TABLE COUNTRY ADD CONSTRAINT XPK_COUNTRY PRIMARY KEY CLUSTERED (Country_Code ASC) go CREATE TABLE AIRPORT –공항 ( idx int IDENTITY ( 1,1 ) , –일련번호 Airport_Code char(3) NOT NULL default ”, –공항코드 Country_Code char(2) NOT NULL default ” — 국가코드 ) go ALTER TABLE AIRPORT –키 설정 ADD CONSTRAINT XPK_AIRPORT PRIMARY KEY CLUSTERED (idx ASC,Airport_Code ASC) go ALTER TABLE AIRPORT –관계 ADD CONSTRAINT R_01 FOREIGN KEY (Country_Code) REFERENCES COUNTRY(Country_Code) ON DELETE CASCADE–부모 삭제시 자식테이블도 삭제 ON UPDATE NO ACTION go |