· 8 years ago · May 17, 2018, 05:22 PM
1DROP TABLE IF EXISTS adress, zipcode, comp;
2DROP TABLE IF EXISTS tabel_address, tabel_zipcode, tabel_comp, tabel_city;
3
4CREATE TABLE tabel_city(
5city_key int(100) NOT NULL AUTO_INCREMENT PRIMARY KEY,
6city varchar(200) NOT NULL)
7ENGINE=InnoDB DEFAULT CHARSET=latin1;
8
9CREATE TABLE tabel_comp (
10comp_key int(100) NOT NULL AUTO_INCREMENT PRIMARY KEY,
11comp varchar(200) NOT NULL)
12ENGINE=InnoDB DEFAULT CHARSET=latin1;
13
14CREATE TABLE tabel_zipcode(
15zipcode_key int(100) NOT NULL AUTO_INCREMENT PRIMARY KEY,
16zipcode varchar(200) NOT NULL)
17ENGINE=InnoDB DEFAULT CHARSET=latin1;
18
19CREATE TABLE tabel_address(
20address_key int(100) NOT NULL PRIMARY KEY AUTO_INCREMENT PRIMARY KEY,
21address varchar(200) NOT NULL,
22comp_key int(100),
23city_key int(100),
24zipcode_key int(100),
25
26CONSTRAINT comp_key_fk FOREIGN KEY (comp_key) REFERENCES tabel_comp(comp_key),
27CONSTRAINT city_key_fk FOREIGN KEY (city_key) REFERENCES tabel_city(city_key),
28CONSTRAINT zipcode_key_fk FOREIGN KEY (zipcode_key) REFERENCES tabel_zipcode(zipcode_key))
29 ENGINE=InnoDB DEFAULT CHARSET=latin1;