forked from Baeldung/sql-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuniversity-postgresql.sql
More file actions
46 lines (37 loc) · 955 Bytes
/
university-postgresql.sql
File metadata and controls
46 lines (37 loc) · 955 Bytes
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
-- SQL script to create DB, and tables. Then insert data in each table
-- Run the DROP statment by itself
DROP DATABASE IF EXISTS University;
-- Create the new Database
CREATE DATABASE University ENCODING 'UTF8';
-- Select the new university database and open a new query
SET SCHEMA 'public';
-- Create Tables
CREATE TABLE Department
(
id INT PRIMARY KEY NOT Null,
name VARCHAR (50),
code VARCHAR (4),
UNIQUE (id)
);
CREATE TABLE Student
(
id INT PRIMARY KEY NOT null,
name VARCHAR (60),
national_id BIGINT NOT Null,
birth_date DATE,
enrollment_date DATE,
graduation_date DATE,
gpa REAL,
UNIQUE (id)
);
CREATE TABLE Course
(
id VARCHAR (10) PRIMARY KEY NOT Null,
name VARCHAR(60),
textbook VARCHAR(100),
credits INT,
is_active VARCHAR(10),
department_id INT,
CONSTRAINT course_department_id_fkey FOREIGN KEY(department_id) REFERENCES Department(id),
UNIQUE (id)
);