-
Notifications
You must be signed in to change notification settings - Fork 2
/
数据库构建.sql
177 lines (85 loc) · 2.5 KB
/
数据库构建.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*action!!!
与ndm文件导出的区别:
1.course表的id属性有自增(INDENTITY(1,1))*/
CREATE TABLE [teacher] (
[id] int NOT NULL,
[name] varchar(255) NOT NULL,
[passwd] varchar(255) NOT NULL,
PRIMARY KEY ([id])
)
GO
CREATE TABLE [class] (
[id] int NOT NULL,
PRIMARY KEY ([id])
)
GO
CREATE TABLE [commit] (
[id] int NOT NULL,
[committer_id] int NOT NULL,
[course_id] int NOT NULL,
[commit_text] varchar(255) NOT NULL,
CONSTRAINT [IX_commit] UNIQUE NONCLUSTERED ([committer_id],[course_id]
),
PRIMARY KEY ([committer_id], [course_id], [id])
)
GO
CREATE TABLE [course] (
[id] int IDENTITY(1,1) NOT NULL,
[name] varchar(50) NOT NULL,
[teacher_id] int NOT NULL,
PRIMARY KEY ([id])
)
GO
CREATE TABLE [major] (
[class_id] int NOT NULL,
[course_id] int NOT NULL,
PRIMARY KEY ([class_id], [course_id])
)
GO
CREATE TABLE [student] (
[id] int NOT NULL,
[class_id] int NOT NULL,
[name] varchar(255) NOT NULL,
[passwd] varchar(255) NOT NULL,
PRIMARY KEY ([id])
)
GO
CREATE TABLE [extra] (
[student_id] int NOT NULL,
[course_id] int NOT NULL,
PRIMARY KEY ([student_id], [course_id])
)
GO
CREATE TABLE [ranks] (
[commit_id] int NOT NULL,
[items_id] int NOT NULL,
[rank] tinyint NOT NULL,
PRIMARY KEY ([items_id], [commit_id])
)
GO
CREATE TABLE [rank_items] (
[id] int NOT NULL,
[text] varchar(255) NOT NULL,
PRIMARY KEY ([id])
)
GO
ALTER TABLE [commit] ADD CONSTRAINT [fk_commit_course_2] FOREIGN KEY ([course_id]) REFERENCES [course] ([id])
GO
ALTER TABLE [major] ADD CONSTRAINT [fk_cl_co_class_1] FOREIGN KEY ([class_id]) REFERENCES [class] ([id])
GO
ALTER TABLE [major] ADD CONSTRAINT [fk_cl_co_course_1] FOREIGN KEY ([course_id]) REFERENCES [course] ([id])
GO
ALTER TABLE [course] ADD CONSTRAINT [fk_course_account_1] FOREIGN KEY ([teacher_id]) REFERENCES [teacher] ([id])
GO
ALTER TABLE [student] ADD CONSTRAINT [fk_student_class_1] FOREIGN KEY ([class_id]) REFERENCES [class] ([id])
GO
ALTER TABLE [extra] ADD CONSTRAINT [fk_extra_student_1] FOREIGN KEY ([student_id]) REFERENCES [student] ([id])
GO
ALTER TABLE [extra] ADD CONSTRAINT [fk_extra_course_1] FOREIGN KEY ([course_id]) REFERENCES [course] ([id])
GO
ALTER TABLE [commit] ADD CONSTRAINT [fk_commit_student_1] FOREIGN KEY ([committer_id]) REFERENCES [student] ([id])
GO
ALTER TABLE [ranks] ADD CONSTRAINT [fk_ranks_commit_1] FOREIGN KEY ([commit_id]) REFERENCES [commit] ([id])
GO
ALTER TABLE [ranks] ADD CONSTRAINT [fk_ranks_items_1] FOREIGN KEY ([items_id]) REFERENCES [rank_items] ([id])
GO