-
Notifications
You must be signed in to change notification settings - Fork 0
/
SAMPLE_DATABASE_SCRIPT.sql
70 lines (58 loc) · 1.58 KB
/
SAMPLE_DATABASE_SCRIPT.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
USE master
GO
IF db_id('BlogDB') IS NULL
CREATE DATABASE BlogDB
GO
USE BlogDB
GO
BEGIN
CREATE TABLE tbUsers (
ID int Identity(1,1) PRIMARY KEY,
FullName nvarchar(50) NOT NULL,
BirthDate datetime NOT NULL,
EMail nvarchar(50) NOT NULL
);
CREATE TABLE tbAuthors (
ID int Identity(1,1) PRIMARY KEY,
FullName nvarchar(50) NOT NULL,
BirthDate datetime NOT NULL,
EMail nvarchar(50) NOT NULL
);
CREATE TABLE tbTitles (
ID int Identity(1,1) PRIMARY KEY,
Title nvarchar(50) NOT NULL
);
CREATE TABLE tbSubTitles (
ID int Identity(1,1) PRIMARY KEY,
TitleID int NOT NULL,
SubTitle nvarchar(50) NOT NULL,
FOREIGN KEY (TitleID) REFERENCES tbTitles (ID)
);
CREATE TABLE tbArticles (
ID int Identity(1,1) PRIMARY KEY,
TitleID int NOT NULL,
SubTitleID int NOT NULL,
AuthorID int NOT NULL,
ArticleCaption nvarchar(250),
ArticleContent nvarchar(MAX),
FOREIGN KEY (TitleID) REFERENCES tbTitles (ID),
FOREIGN KEY (SubTitleID) REFERENCES tbSubTitles (ID),
FOREIGN KEY (AuthorID) REFERENCES tbAuthors (ID)
);
CREATE TABLE tbUserLikedTitles(
ID int Identity(1,1) PRIMARY KEY,
UserID int NOT NULL,
TitleID int NOT NULL,
SubTitleID int NOT NULL,
FOREIGN KEY (UserID) REFERENCES tbUsers (ID),
FOREIGN KEY (TitleID) REFERENCES tbTitles (ID),
FOREIGN KEY (SubTitleID) REFERENCES tbSubTitles (ID)
);
CREATE TABLE tbAuthorsOfArticles(
ID int Identity(1,1) PRIMARY KEY,
AuthorID int NOT NULL,
ArticleID int NOT NULL,
FOREIGN KEY (AuthorID) REFERENCES tbAuthors (ID),
FOREIGN KEY (ArticleID) REFERENCES tbArticles (ID)
);
END