This is a team project, up to four people, that aims to provide you some experience in database design. We will explore both theoretical and practical aspects of the database design steps. First, you will design an application and then translate the theoretical concepts into the terms of a concrete DBMS to implement the database.
The objective in this project is to adapt the existing University database from our textbook and to turn in the database of the University of Macau.

A. Discuss the changes your group would like to implement in the existing DB to become UM DB. As follows some suggestions:

· Alter attributes to accommodate data from University of Macau. For example, you need to alter the size of the student ID from (5) to (8) or (11) in order to accommodate DB012345 or D-B0-1234-5.
· The group may change primary keys in case your group think it is necessary.
· The group can add any extra constraints or remove any existing one.
· The group may add attributes if you think necessary.

building 建築物

  1. CREATE TABLE building
  2. (building_id varchar(4) not null,
  3. name varchar(50) not null,
  4. floors numeric(2,0) not null,
  5. primary key (building_id)
  6. )

Example
building_id - E11 or E21A
name - Faculty of Science and Technology
floors - maximum as 4 (how many floors are there)
image.png

classroom

  1. CREATE TABLE classroom
  2. (building_id varchar(4) not null,
  3. room_number varchar(12) not null,
  4. capacity numeric(4,0) not null,
  5. primary key (building_id, room_number),
  6. foreign key (building_id) references building
  7. on delete cascade
  8. )
  • building -> building_id
    1. varchar(15) -> varchar(4)
  • room_number
    1. varchar(7) -> varchar(12)
  • foreign key (building_id) references building on delete cascade

image.png

faculty

  1. CREATE TABLE faculty
  2. (faculty_code varchar(4) not null,
  3. sid_prefix char(1) not null,
  4. name varchar(50) not null,
  5. building_id varchar(4),
  6. primary key (faculty_code),
  7. foreign key (building_id) references building
  8. on delete set null
  9. )

image.png

department

  1. CREATE TABLE department
  2. (dept_id varchar(10) not null,
  3. dept_name varchar(50) not null,
  4. building_id varchar(4),
  5. budget numeric(12,2)
  6. check (budget >= 0) not null,
  7. parent_dept_id varchar(10),
  8. primary key (dept_id),
  9. foreign key (building_id) references building
  10. on delete set null,
  11. foreign key (parent_dept_id) references department
  12. )
  • dept_id
    1. primary key
  • dept_name
    1. varchar(20) -> varchar(50)
    2. remove primary key
  • building -> building_id
    1. varchar(15) -> varchar(4)
  • budget
    1. check (budget > 0) -> check (budget >= 0)
  • parent_dept_id
  • foreign key (building_id) references building on delete set null
  • foreign key (parent_dept_id) references department

image.png

course

  1. CREATE TABLE course
  2. (course_id char(8) not null,
  3. course_old_id char(7),
  4. title varchar(50) not null,
  5. dept_id varchar(10),
  6. credits numeric(2,0)
  7. check (credits > 0) not null,
  8. primary key (course_id),
  9. foreign key (dept_id) references department
  10. on delete set null
  11. )
  • course_id
    1. varchar(8) -> char(8)
  • course_old_id
  • dept_name -> dept_id
    1. varchar(20) -> varchar(10)

image.png

programme

  1. CREATE TABLE programme
  2. (programme_id char(5) not null,
  3. dept_id varchar(10),
  4. credits numeric(3,0) not null,
  5. years numeric(1,0) not null,
  6. primary key (programme_id),
  7. foreign key (dept_id) references department
  8. on delete set null
  9. )

image.png

requires

  1. CREATE TABLE requires
  2. (programme_id char(5) not null,
  3. course_id char(8) not null,
  4. type char(2)
  5. check (type in ('CM', 'GE', 'RE', 'FE', 'MI', 'DE')) not null,
  6. primary key (programme_id, course_id),
  7. foreign key (programme_id) references programme
  8. on delete cascade,
  9. foreign key (course_id) references course
  10. on delete cascade
  11. )

image.png

instructor

  1. CREATE TABLE instructor
  2. (instructor_id varchar(6) not null,
  3. firstname varchar(40) not null,
  4. middlename varchar(40),
  5. lastname varchar(40) not null,
  6. chi_firstname varchar(3),
  7. chi_lastname varchar(2),
  8. birthdate date not null,
  9. address varchar(500) not null,
  10. dept_id varchar(10),
  11. office varchar(12) not null,
  12. salary numeric(8,2) check (salary > 0) not null,
  13. primary key (instructor_id),
  14. foreign key (dept_id) references department
  15. on delete set null
  16. )
  • ID -> instructor_id
    1. varchar(5) -> varchar(6)
  • name -> firstname, middlename, lastname, chi_firstname, chi_lastname
  • birthdate
  • address
  • dept_name -> dept_id
    1. varchar(20) -> varchar(10)
  • salary
    1. check (salary > 29000) -> check (salary >= 0)

image.png

time_slot

  1. CREATE TABLE time_slot
  2. (time_slot_id varchar(4) not null,
  3. day char(1)
  4. check (day in ('M', 'T', 'W', 'H', 'F', 'S', 'U')) not null,
  5. start_time time not null,
  6. end_time time not null,
  7. type varchar(8)
  8. check (type in ('Lecture', 'Tutorial', 'Lab')) not null,
  9. primary key (time_slot_id, day, start_time)
  10. )
  • day
    1. varchar(1) -> char(1)
  • i_ID -> instructor_id
    1. varchar(5) -> varchar(6)
  • start_hr, start_min -> start_time
  • end_hr, end_min -> end_time

image.png

section

  1. CREATE TABLE section
  2. (course_id char(8) not null,
  3. sec_id char(3) not null,
  4. semester varchar(6)
  5. check (semester in ('1', '2', 'Summer')) not null,
  6. year numeric(4,0)
  7. check (year > 1701 and year < 2100) not null,
  8. building_id varchar(4),
  9. room_number varchar(12),
  10. alt_room_number varchar(12),
  11. time_slot_id varchar(4),
  12. primary key (course_id, sec_id, semester, year),
  13. foreign key (course_id) references course
  14. on delete cascade,
  15. foreign key (building_id, room_number) references classroom
  16. on delete set null
  17. )
  • course_id
    1. varchar(8) -> char(8)
  • sec_id
    1. varchar(8) -> char(3)
  • semester
    1. check (semester in (‘Fall’, ‘Winter’, ‘Spring’, ‘Summer’)) -> check (semester in (‘1’, ‘2’, ‘Summer’))
  • building -> building_id
    1. varchar(15) -> varchar(4)
  • room_number
    1. varchar(7) -> varchar(12)
  • alt_room_number

image.png

teaches

  1. CREATE TABLE teaches
  2. (instructor_id varchar(6) not null,
  3. course_id char(8) not null,
  4. sec_id char(3) not null,
  5. semester varchar(6) not null,
  6. year numeric(4,0) not null,
  7. primary key (instructor_id, course_id, sec_id, semester, year),
  8. foreign key (course_id, sec_id, semester, year) references section
  9. on delete cascade,
  10. foreign key (instructor_id) references instructor
  11. on delete cascade
  12. )
  • ID -> instructor_id
    1. varchar(5) -> varchar(6)
  • course_id
    1. varchar(8) -> char(8)
  • sec_id
    1. varchar(8) -> char(3)

student

  1. CREATE TABLE student
  2. (student_id char(7) not null,
  3. firstname varchar(40) not null,
  4. middlename varchar(40),
  5. lastname varchar(40) not null,
  6. chi_firstname varchar(3),
  7. chi_lastname varchar(2),
  8. birthdate date not null,
  9. address varchar(500) not null,
  10. register_date date not null,
  11. programme_id char(5),
  12. primary key (student_id),
  13. foreign key (programme_id) references programme
  14. on delete set null
  15. )
  • ID -> student_id
    1. varchar(5) -> char(7)
  • name -> firstname, middlename, lastname, chi_firstname, chi_lastname
  • birthdate
  • address
  • register_date
  • programme_id
  • tot_cred
    1. removed, calculate by programme, requires, and course table

image.png

takes

  1. CREATE TABLE takes
  2. (student_id char(7) not null,
  3. course_id char(8) not null,
  4. sec_id char(3) not null,
  5. semester varchar(6) not null,
  6. year numeric(4,0) not null,
  7. grade varchar(2),
  8. primary key (student_id, course_id, sec_id, semester, year),
  9. foreign key (course_id, sec_id, semester, year) references section
  10. on delete cascade,
  11. foreign key (student_ID) references student
  12. on delete cascade
  13. )
  • ID -> student_id
    1. varchar(5) -> char(7)
  • course_id
    1. varchar(8) -> char(8)
  • sec_id
    1. varchar(8) -> char(3)

advisor

  1. CREATE TABLE advisor
  2. (student_id char(7) not null,
  3. instructor_id varchar(6) not null,
  4. primary key (student_id, instructor_id),
  5. foreign key (instructor_id) references instructor
  6. on delete cascade,
  7. foreign key (student_ID) references student
  8. on delete cascade
  9. )
  • s_ID -> student_id
    1. varchar(5) -> char(7)
  • i_ID -> instructor_id
    1. varchar(5) -> varchar(6)
  • primary key
    1. (s_ID) -> (student_id, instructor_id)
  • foreign key
    1. on delete set null -> on delete set cascade

prereq

  1. CREATE TABLE prereq
  2. (course_id char(8) not null,
  3. prereq_id char(8) not null,
  4. primary key (course_id, prereq_id),
  5. foreign key (course_id) references course
  6. on delete cascade,
  7. foreign key (prereq_id) references course
  8. )
  • course_id
    1. varchar(8) -> char(8)
  • prereq_id
    1. varchar(8) -> char(8)

B. Specify the assumptions about the database in English (informally).

Here you give the proper explanation of the attributes, keys, the nature of relationships between entities, etc. For those obvious assumptions such as students can take several courses, be brief. However, for those more complex relationships you should explain in a more detailed way. In addition, do not make too many simplifying assumptions.

C. Give an ER diagram,

which will reflect your choice of the entity sets, their relevant attributes, and the relationships among them. Again, make your relationships realistic and meaningful.
PROJ01 CISC3000 UM Database - 图12

D. Convert the ER diagram into a relational database schema.

List all of your SQL statements for creating or altering tables, inserting or updating tables and so on.

E. Samples from your database.

Few tasks to be made here:

· Insert or update the values of the altered attributes.

The number of tuples in the relations should not be different from the existing relations. List all relations and their contents.

Table building

  1. INSERT building (building_id, name, floors) VALUES
  2. ('E1', 'University Gallery', 2),
  3. ('E11', 'Faculty of Science and Technology', 4),
  4. ('E12', 'Faculty of Health Sciences', 4),
  5. ('E2', 'UM Wu Yee Sun Library', 6),
  6. ('E21A', 'Faculty of Arts and Humanities', 4),
  7. ('E21B', 'Faculty of Social Sciences', 4),
  8. ('E22', 'Faculty of Business Administration', 4),
  9. ('E31', 'Student Activity Centre', 3),
  10. ('E32', 'Faculty of Law', 4),
  11. ('E33', 'Faculty of Education', 4),
  12. ('E34', 'Cultural Building', 4),
  13. ('E4', 'Anthony Lau Building', 4),
  14. ('E5', 'Central Teaching Building', 4),
  15. ('E6', 'Central Teaching Building', 4),
  16. ('E7', 'Central Teaching Building', 3)

Table classroom

  1. INSERT classroom (building_id, room_number, capacity) VALUES
  2. ('E11', 'E11-1006', 80),
  3. ('E11', 'E11-1015', 80),
  4. ('E11', 'E11-1028', 80),
  5. ('E11', 'E11-2032', 120),
  6. ('E11', 'E11-G015', 150),
  7. ('E21A', 'E21-G035', 100),
  8. ('E21A', 'E21-G036', 100),
  9. ('E22', 'E22-1011', 50),
  10. ('E22', 'E22-2012', 50),
  11. ('E4', 'E6-G078', 300)

Table faculty

  1. INSERT faculty (faculty_code, sid_prefix, name, building_id) VALUES
  2. ('FAH', 'A', 'Faculty of Arts and Humanities', 'E21A'),
  3. ('FBA', 'B', 'Faculty of Business Administration', 'E22'),
  4. ('FED', 'H', 'Faculty of Education', 'E33'),
  5. ('FHS', 'C', 'Faculty of Health Sciences', 'E12'),
  6. ('FLL', 'L', 'Faculty of Law', 'E32'),
  7. ('FSS', 'S', 'Faculty of Social Sciences', 'E21B'),
  8. ('FST', 'D', 'Faculty of Science and Technology', 'E11')

Table department

  1. INSERT department (dept_id, dept_name, building_id, budget, faculty_code, parent_dept_id) VALUES
  2. ('BEC', 'Department of Business Economics', 'E22', 5000000.00, 'FBA', NULL),
  3. ('CEE', 'Department of Civil and Environmental Engineering', 'E11', 3000000.00, 'FST', NULL),
  4. ('CIS', 'Department of Computer and Information Science', 'E11', 3000000.00, 'FST', NULL),
  5. ('DAIM', 'Department of Accounting and Information Management', 'E22', 3000000.00, 'FBA', NULL),
  6. ('FNC', 'Department of Finance', 'E22', 7000000.00, 'FBA', NULL),
  7. ('GLS', 'Department of Global Legal Studies', 'E33', 200000000.00, 'FLL', NULL),
  8. ('MAT', 'Department of Mathematics', 'E11', 2000000.00, 'FST', NULL),
  9. ('PC', 'Department of Physics and Chemistry', 'E11', 3000000.00, 'FST', NULL),
  10. ('SAO', 'Student Affairs Office', 'E31', 6000000.00, NULL, NULL),
  11. ('SAO-SRS', 'Student Affairs Office - Student Resources Section', 'E31', 2000000.00, NULL, 'SAO')

· Create and list ten reasonable queries (containing ‘join’ or ‘aggregate’).

Explain and execute them, and print the contents for checking.
Submit a report containing all the five sections (A to E) described above.