forked from Baeldung/sql-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuniversity-sqlserver.sql
More file actions
44 lines (39 loc) · 941 Bytes
/
university-sqlserver.sql
File metadata and controls
44 lines (39 loc) · 941 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
-- SQL script to create DB, and tables. Then insert data in each table
-- Run these 2 statements in a separate query
IF NOT EXISTS (SELECT * FROM sys.databases WHERE name = 'University')
BEGIN
CREATE DATABASE University;
END
GO
-- Change schema to University
USE University;
-- 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 FLOAT(4),
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)
);