-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
38 lines (30 loc) · 1.25 KB
/
schema.sql
File metadata and controls
38 lines (30 loc) · 1.25 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 communications;
CREATE DATABASE communications;
USE communications;
CREATE TABLE contacts (
id INT PRIMARY KEY AUTO_INCREMENT,
number VARCHAR(25) NOT NULL,
name VARCHAR(50)
);
CREATE TABLE messages (
id INT PRIMARY KEY AUTO_INCREMENT,
contactId INT NOT NULL,
FOREIGN KEY (contactId) REFERENCES contacts(id) ON DELETE CASCADE,
time VARCHAR(25),
content VARCHAR(250),
sender VARCHAR(25),
sendee VARCHAR(25)
);
INSERT INTO contacts (number) VALUES ("+15103213810");
INSERT INTO contacts (number) VALUES ("+15233243412");
INSERT INTO contacts (number) VALUES ("+12384712749");
INSERT INTO messages (content, sender, sendee, contactId) VALUES ("Dude did you shower today?","+15103213810", "+12345678901", 1);
INSERT INTO messages (content, sender, sendee, contactId) VALUES ("How's the project going?","+15233243412", "+12345678902", 2);
INSERT INTO messages (content, sender, sendee, contactId) VALUES ("That looks AWESOME!!","+15233243412", "+12345678902", 2);
-- CREATE TABLE contact_messages (
-- SELECT contacts.contact_id, contacts.number, messages.message_id, messages.sender
-- INTO contact_messages
-- FROM contacts
-- INNER JOIN messages
-- ON contacts.number = messages.sender
-- );