-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.sql
49 lines (42 loc) · 1.39 KB
/
database.sql
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
39
40
41
42
43
44
45
46
47
48
49
DROP DATABASE IF EXISTS contact_management_db;
CREATE DATABASE contact_management_db;
CREATE TABLE users (
username CHARACTER VARYING(100) NOT NULL,
password CHARACTER VARYING(100) NOT NULL,
name CHARACTER VARYING(100) NOT NULL,
token CHARACTER VARYING(100),
token_expired_at BIGINT,
PRIMARY KEY(username),
UNIQUE (token)
);
SELECT * FROM users;
CREATE TABLE contacts(
id CHARACTER VARYING(100) NOT NULL,
username CHARACTER VARYING(100) NOT NULL,
first_name CHARACTER VARYING(100) NOT NULL,
last_name CHARACTER VARYING(100),
phone CHARACTER VARYING(100),
email CHARACTER VARYING(100),
PRIMARY KEY(id),
CONSTRAINT fk_users_contacts
FOREIGN KEY(username)
REFERENCES users(username)
);
SELECT * FROM contacts;
CREATE TABLE addresses(
id CHARACTER VARYING(100) NOT NULL,
contact_id CHARACTER VARYING(100) NOT NULL,
street CHARACTER VARYING(200),
city CHARACTER VARYING(100),
province CHARACTER VARYING(100),
country CHARACTER VARYING(100) NOT NULL,
postal_code CHARACTER VARYING(10),
PRIMARY KEY(id),
CONSTRAINT fk_contacts_addresses
FOREIGN KEY(contact_id) REFERENCES contacts(id)
);
SELECT * FROM addresses;
--use this for manual test
DELETE FROM addresses WHERE id = public.addresses.id;
DELETE FROM contacts WHERE id = public.contacts.id;
DELETE FROM users WHERE username = public.users.username;