-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate.sql
More file actions
38 lines (34 loc) · 1.08 KB
/
create.sql
File metadata and controls
38 lines (34 loc) · 1.08 KB
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
31
32
33
34
35
36
37
38
DROP DATABASE IF EXISTS kbank;
CREATE DATABASE kbank;
USE kbank;
CREATE TABLE postcodes(
postcode varchar(8) PRIMARY KEY,
country varchar(20) NOT NULL,
town varchar(20) NOT NULL,
county varchar(20) NOT NULL
);
CREATE TABLE customers(
id int AUTO_INCREMENT NOT NULL PRIMARY KEY,
firstName varchar(20) NOT NULL,
lastName varchar(20) NOT NULL,
dateOfBirth date NOT NULL,
gender char(1) NOT NULL,
address varchar(30) NOT NULL,
phoneNumber varchar(12) NOT NULL,
email varchar(25) NOT NULL,
postcode varchar(8) NOT NULL,
FOREIGN KEY (postcode) REFERENCES postcodes(postcode)
);
CREATE TABLE accounts(
accountNumber int(8) ZEROFILL AUTO_INCREMENT NOT NULL PRIMARY KEY,
balance decimal(13,2) DEFAULT 0,
dateOfCreation date,
overdraft decimal(7,2) DEFAULT 0 NOT NULL
);
CREATE TABLE customers_accounts(
customerID int,
accountNumber int(8) ZEROFILL NOT NULL,
PRIMARY KEY (customerID, accountNumber),
FOREIGN KEY (customerID) REFERENCES customers(id),
FOREIGN KEY (accountNumber) REFERENCES accounts(accountNumber)
);