-
Notifications
You must be signed in to change notification settings - Fork 0
/
tables.sql
executable file
·51 lines (40 loc) · 1.58 KB
/
tables.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
50
51
DROP TABLE IF EXISTS articles;
DROP TABLE IF EXISTS users;
DROP TABLE IF EXISTS role;
DROP TABLE IF EXISTS categories;
CREATE TABLE role
(
rolecode varchar(50) NOT NULL,
rolename varchar(50) NOT NULL,
PRIMARY KEY (rolecode)
);
INSERT INTO role VALUES('super','Administrator');
INSERT INTO role VALUES('user','Author');
CREATE TABLE users
(
name varchar(255) NOT NULL,
password varchar(60) NOT NULL,
rolecode varchar(50) NOT NULL,
PRIMARY KEY (name),
FOREIGN KEY (rolecode) REFERENCES role(rolecode)
);
INSERT INTO users (name,password,rolecode) VALUES("admin","pass","super");
CREATE TABLE articles
(
id smallint unsigned NOT NULL auto_increment,
author varchar(255) NOT NULL,
publicationDate date NOT NULL, # When the article was published
title varchar(255) NOT NULL, # Full title of the article
summary text NOT NULL, # A short summary of the article
content mediumtext NOT NULL, # The HTML content of the article
PRIMARY KEY (id),
FOREIGN KEY (author) REFERENCES users(name)
);
CREATE TABLE categories
(
id smallint unsigned NOT NULL auto_increment,
name varchar(255) NOT NULL, # Name of the category
description text NOT NULL, # A short description of the category
PRIMARY KEY (id)
);
ALTER TABLE articles ADD categoryId smallint unsigned NOT NULL AFTER publicationDate;