-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommands.sql
More file actions
executable file
·39 lines (24 loc) · 1.05 KB
/
commands.sql
File metadata and controls
executable file
·39 lines (24 loc) · 1.05 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
/* 'message' be deleted first, because of the cascading constraints*/
DROP TABLE IF EXISTS `message`;
DROP TABLE IF EXISTS `customer`;
DROP TABLE IF EXISTS `recipient`;
CREATE TABLE `customer` (
`customer_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL DEFAULT '',
PRIMARY KEY (`customer_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `recipient` (
`recipient_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL DEFAULT '',
PRIMARY KEY (`recipient_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `message` (
`customer_id` int(10) unsigned NOT NULL DEFAULT '0',
`recipient_id` int(10) unsigned NOT NULL DEFAULT '0',
`message` text NOT NULL,
`received` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
INDEX recipient_idx (recipient_id),
FOREIGN KEY (customer_id) REFERENCES customer(customer_id) ON DELETE CASCADE,
INDEX customer_idx (customer_id),
FOREIGN KEY (recipient_id) REFERENCES recipient(recipient_id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;