-
Notifications
You must be signed in to change notification settings - Fork 0
/
university_management.sql
275 lines (238 loc) · 8.27 KB
/
university_management.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
--
-- PostgreSQL database dump
--
-- Dumped from database version 14.13 (Homebrew)
-- Dumped by pg_dump version 14.13 (Homebrew)
SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;
--
-- Name: address; Type: TYPE; Schema: public; Owner: database_user
--
CREATE TYPE public.address AS (
street character varying(50),
city character varying(30),
zip_code character(6)
);
ALTER TYPE public.address OWNER TO database_user;
SET default_tablespace = '';
SET default_table_access_method = heap;
--
-- Name: course; Type: TABLE; Schema: public; Owner: database_user
--
CREATE TABLE public.course (
course_id integer NOT NULL,
course_name character varying(100),
credits integer
);
ALTER TABLE public.course OWNER TO database_user;
--
-- Name: course_course_id_seq; Type: SEQUENCE; Schema: public; Owner: database_user
--
CREATE SEQUENCE public.course_course_id_seq AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1;
ALTER TABLE public.course_course_id_seq OWNER TO database_user;
--
-- Name: course_course_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: database_user
--
ALTER SEQUENCE public.course_course_id_seq OWNED BY public.course.course_id;
--
-- Name: enrollment; Type: TABLE; Schema: public; Owner: database_user
--
CREATE TABLE public.enrollment (
student_id integer NOT NULL,
course_id integer NOT NULL,
grade character(1)
);
ALTER TABLE public.enrollment OWNER TO database_user;
--
-- Name: person; Type: TABLE; Schema: public; Owner: database_user
--
CREATE TABLE public.person (
person_id integer NOT NULL,
first_name character varying(50),
last_name character varying(50),
dob date,
address public.address
);
ALTER TABLE public.person OWNER TO database_user;
--
-- Name: person_person_id_seq; Type: SEQUENCE; Schema: public; Owner: database_user
--
CREATE SEQUENCE public.person_person_id_seq AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1;
ALTER TABLE public.person_person_id_seq OWNER TO database_user;
--
-- Name: person_person_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: database_user
--
ALTER SEQUENCE public.person_person_id_seq OWNED BY public.person.person_id;
--
-- Name: professor; Type: TABLE; Schema: public; Owner: database_user
--
CREATE TABLE public.professor (
professor_id integer NOT NULL,
hire_date date
) INHERITS (public.person);
ALTER TABLE public.professor OWNER TO database_user;
--
-- Name: professor_professor_id_seq; Type: SEQUENCE; Schema: public; Owner: database_user
--
CREATE SEQUENCE public.professor_professor_id_seq AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1;
ALTER TABLE public.professor_professor_id_seq OWNER TO database_user;
--
-- Name: professor_professor_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: database_user
--
ALTER SEQUENCE public.professor_professor_id_seq OWNED BY public.professor.professor_id;
--
-- Name: student; Type: TABLE; Schema: public; Owner: database_user
--
CREATE TABLE public.student (
student_id integer NOT NULL,
enrollment_year integer
) INHERITS (public.person);
ALTER TABLE public.student OWNER TO database_user;
--
-- Name: student_student_id_seq; Type: SEQUENCE; Schema: public; Owner: database_user
--
CREATE SEQUENCE public.student_student_id_seq AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1;
ALTER TABLE public.student_student_id_seq OWNER TO database_user;
--
-- Name: student_student_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: database_user
--
ALTER SEQUENCE public.student_student_id_seq OWNED BY public.student.student_id;
--
-- Name: course course_id; Type: DEFAULT; Schema: public; Owner: database_user
--
ALTER TABLE ONLY public.course
ALTER COLUMN course_id
SET DEFAULT nextval('public.course_course_id_seq'::regclass);
--
-- Name: person person_id; Type: DEFAULT; Schema: public; Owner: database_user
--
ALTER TABLE ONLY public.person
ALTER COLUMN person_id
SET DEFAULT nextval('public.person_person_id_seq'::regclass);
--
-- Name: professor person_id; Type: DEFAULT; Schema: public; Owner: database_user
--
ALTER TABLE ONLY public.professor
ALTER COLUMN person_id
SET DEFAULT nextval('public.person_person_id_seq'::regclass);
--
-- Name: professor professor_id; Type: DEFAULT; Schema: public; Owner: database_user
--
ALTER TABLE ONLY public.professor
ALTER COLUMN professor_id
SET DEFAULT nextval('public.professor_professor_id_seq'::regclass);
--
-- Name: student person_id; Type: DEFAULT; Schema: public; Owner: database_user
--
ALTER TABLE ONLY public.student
ALTER COLUMN person_id
SET DEFAULT nextval('public.person_person_id_seq'::regclass);
--
-- Name: student student_id; Type: DEFAULT; Schema: public; Owner: database_user
--
ALTER TABLE ONLY public.student
ALTER COLUMN student_id
SET DEFAULT nextval('public.student_student_id_seq'::regclass);
--
-- Data for Name: course; Type: TABLE DATA; Schema: public; Owner: database_user
--
COPY public.course (course_id, course_name, credits)
FROM stdin;
1 Database Systems 3 2 Operating Systems 4 \.--
-- Data for Name: enrollment; Type: TABLE DATA; Schema: public; Owner: database_user
--
COPY public.enrollment (student_id, course_id, grade)
FROM stdin;
1 1 A 1 2 B \.--
-- Data for Name: person; Type: TABLE DATA; Schema: public; Owner: database_user
--
COPY public.person (person_id, first_name, last_name, dob, address)
FROM stdin;
1 John Doe 2000 -01 -01 ("123 Main St", Springfield, 123456) 3 Jane Smith 1980 -05 -20 ("456 Oak St", Greenville, 654321) \.--
-- Data for Name: professor; Type: TABLE DATA; Schema: public; Owner: database_user
--
COPY public.professor (
person_id,
first_name,
last_name,
dob,
address,
professor_id,
hire_date
)
FROM stdin;
4 \ N \ N \ N \ N 1 2010 -08 -15 \.--
-- Data for Name: student; Type: TABLE DATA; Schema: public; Owner: database_user
--
COPY public.student (
person_id,
first_name,
last_name,
dob,
address,
student_id,
enrollment_year
)
FROM stdin;
2 \ N \ N \ N \ N 1 2020 \.--
-- Name: course_course_id_seq; Type: SEQUENCE SET; Schema: public; Owner: database_user
--
SELECT pg_catalog.setval('public.course_course_id_seq', 2, true);
--
-- Name: person_person_id_seq; Type: SEQUENCE SET; Schema: public; Owner: database_user
--
SELECT pg_catalog.setval('public.person_person_id_seq', 4, true);
--
-- Name: professor_professor_id_seq; Type: SEQUENCE SET; Schema: public; Owner: database_user
--
SELECT pg_catalog.setval('public.professor_professor_id_seq', 1, true);
--
-- Name: student_student_id_seq; Type: SEQUENCE SET; Schema: public; Owner: database_user
--
SELECT pg_catalog.setval('public.student_student_id_seq', 1, true);
--
-- Name: course course_pkey; Type: CONSTRAINT; Schema: public; Owner: database_user
--
ALTER TABLE ONLY public.course
ADD CONSTRAINT course_pkey PRIMARY KEY (course_id);
--
-- Name: enrollment enrollment_pkey; Type: CONSTRAINT; Schema: public; Owner: database_user
--
ALTER TABLE ONLY public.enrollment
ADD CONSTRAINT enrollment_pkey PRIMARY KEY (student_id, course_id);
--
-- Name: person person_pkey; Type: CONSTRAINT; Schema: public; Owner: database_user
--
ALTER TABLE ONLY public.person
ADD CONSTRAINT person_pkey PRIMARY KEY (person_id);
--
-- Name: professor professor_pkey; Type: CONSTRAINT; Schema: public; Owner: database_user
--
ALTER TABLE ONLY public.professor
ADD CONSTRAINT professor_pkey PRIMARY KEY (professor_id);
--
-- Name: student student_pkey; Type: CONSTRAINT; Schema: public; Owner: database_user
--
ALTER TABLE ONLY public.student
ADD CONSTRAINT student_pkey PRIMARY KEY (student_id);
--
-- Name: enrollment enrollment_course_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: database_user
--
ALTER TABLE ONLY public.enrollment
ADD CONSTRAINT enrollment_course_id_fkey FOREIGN KEY (course_id) REFERENCES public.course(course_id);
--
-- Name: enrollment enrollment_student_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: database_user
--
ALTER TABLE ONLY public.enrollment
ADD CONSTRAINT enrollment_student_id_fkey FOREIGN KEY (student_id) REFERENCES public.student(student_id);
--
-- PostgreSQL database dump complete
--