Skip to content Skip to navigation

Connexions

You are here: Home » Content » Homework 2

Navigation

Lenses

What is a lens?

Definition of a lens

Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

Who can create a lens?

Any individual member, a community, or a respected organization.

What are tags? tag icon

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

This content is ...

Affiliated with (What does "Affiliated with" mean?)

This content is either by members of the organizations listed or about topics related to the organizations listed. Click each link to see a list of all content affiliated with the organization.
  • VOCW

    This module is included inLens: Vietnam OpenCourseWare's Lens
    By: Vietnam OpenCourseWare

    Click the "VOCW" link to see all content affiliated with them.

Recently Viewed

This feature requires Javascript to be enabled.
 

Homework 2

Module by: Nguyen Kim Anh. E-mail the author

SQL Queries

Due date: 5pm Friday week 9

Late submission is not acceptable

Question 1

(Based on exercise 8.7 in the textbook – Fundamentals of Database Systems)

Consider the following database schema

Student(Name, Student_number, Class, Major)

Course(Course_name, Course_number, Credit, Department)

Prerequisite (Course_number, Prerequisite_number)

Section (Section_identifier, Course_number, Semester, Year, Instructor)

Mark_Report(Student_number, Section_identifier, Mark)

  • What are the referential integrity constraints that should hold on the schema?
  • Write appropriate SQL Data Definition Language statements to define the database.

Question 2

Consider the following database schema

Student (StudentId, FullName, BDate,Major, Stage)

Course (Code, Name, LecturerName)

Enrol(StudentId, CourseCode, Session, Mark)

Specify the following queries in SQL

  • Find the name of all first year (stage 1) students who are enrolled in a course taught by Do Minh
  • Find the name of all student who enrolled in course Database System in session S1-07 and had failed mark (mark < 5)
  • Find the names of lecturers who have taught more than 5 courses
  • For student with id ‘20062020 ‘, find all courses and corresponding mark that student had enrolled in session S1-07
  • How many Computer Science student are currently in stage 3?
  • For each student in stage 1, print the student id and the average mark.
  • Find the names of students who are not enrolled in any courses.
  • Find the name of the student(s) who had the highest mark for course Database System in session S2-07

Question 3

Consider the following database schema. An employee can work in more than one department; the pct_time field of the Works relation shows the percentage of time that a given employee works in a given department.

Emp(eid, ename, age, salary)

Dept(did, budget, managerid)

Works(eid, did, pct_time)

The following SQL DDL statements are used to define the database.

CREATE TABLE Employees (

eid INTEGER,

ename VARCHAR(30),

age INTEGER,

salary REAL,

PRIMARY KEY (eid)

);

CREATE TABLE Departments (

did INTEGER,

dname VARCHAR(20),

budget REAL,

manager INTEGER,

PRIMARY KEY (did),

FOREIGN KEY (manager) REFERENCES Employees(eid)

);

CREATE TABLE WorksIn (

eid INTEGER,

did INTEGER,

pct_time REAL,

PRIMARY KEY (eid,did),

FOREIGN KEY (eid) REFERENCES Employees(eid),

FOREIGN KEY (did) REFERENCES Departments(did)

);

Give the answer for each of the following question in SQL

  • Add a constraint to the CREATE TABLE statements above to ensure that every department must have a manager.
  • Add a constraint to the CREATE TABLE statements above to ensure that employees’s salary is exceed the low-bar of 15,000
  • When an employee is removed from the database, it makes sense to also delete all of the records that show which departments he/she works for. Modify the CREATE TABLE statements above to ensure that this occurs.
  • The company has several years of growth and high profits, and considers that the Sales department is primarily responsible for this. Write an SQL statement to give all employees in the Sales department a 10% pay rise.
  • A new government initiative to get more young people into work cuts the salary levels of all workers under 25 by 20%. Write an SQL statement to implement this policy change.
  • Find the names and ages of each employee who works in both the Hardware and Software department.
  • Find the name and pct_time of all employees who works for department Software with less than 50% time effort.
  • For each department with more than 20 employees , print the department id together with the number of employees that work in that department.
  • If a manager manages more than one department, he/she is said to control the sum of all the budgets for those departments. Find the managerids of managers who control more than 5,000,000.

Content actions

Download module as:

PDF | EPUB (?)

What is an EPUB file?

EPUB is an electronic book format that can be read on a variety of mobile devices.

Downloading to a reading device

For detailed instructions on how to download this content's EPUB to your specific device, click the "(?)" link.

| More downloads ...

Add module to:

My Favorites (?)

'My Favorites' is a special kind of lens which you can use to bookmark modules and collections. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need an account to use 'My Favorites'.

| A lens I own (?)

Definition of a lens

Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

Who can create a lens?

Any individual member, a community, or a respected organization.

What are tags? tag icon

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

| External bookmarks