# { PreviousEducation ( CollegeName, StartDate, EndDate, { Degree (DegreeName, Month, Year) }, { Transcript (CourseName, Semester, Year, Grade) } ) }

Save this PDF as:
Size: px
Start display at page:

Download "{ PreviousEducation ( CollegeName, StartDate, EndDate, { Degree (DegreeName, Month, Year) }, { Transcript (CourseName, Semester, Year, Grade) } ) }"

## Transcription

1 Tutorial 3 Solution Exercise1: Exercise 2: { PreviousEducation ( CollegeName, StartDate, EndDate, { Degree (DegreeName, Month, Year) }, { Transcript (CourseName, Semester, Year, Grade) } ) } Exercise 3: (a) Entity types: BANK, ACCOUNT, CUSTOMER, LOAN (b) Weak entity type: BANK-BRANCH. Partial key: BranchNo. Identifying relationship: BRANCHES. (c) The partial key BranchNo in BANK-BRANCH specifies that the same BranchNo value may occur under different BANKs. The identifying relationship BRANCHES specifies that BranchNo values are uniquely assigned for those BANK-BRANCH entities that are related to the same BANK entity. Hence, the combination of BANK Code and BranchNo together constitute a full identifier for a BANK-BRANCH.

2 (d) Relationship Types: BRANCHES, ACCTS, LOANS, A-C, L-C. The (min, max) constraints are shown below. (e) The requirements may be stated as follows: Each BANK has a unique Code, as well as a Name and Address. Each BANK is related to one or more BANK-BRANCHes, and the BranhNo is unique among each set of BANK-BRANCHes that are related to the same BANK. Each BANK-BRANCH has an Address. Each BANK-BRANCH has zero or more LOANS and zero or more ACCTS. Each ACCOUNT has an AcctNo (unique), Balance, and Type and is related to exactly one BANK-BRANCH and to at least one CUSTOMER. Each LOAN has a LoanNo (unique), Amount, and Type and is related to exactly one BANK-BRANCH and to at least one CUSTOMER. Each CUSTOMER has an SSN (unique), Name, Phone, and Address, and is related to zero or more ACCOUNTs and to zero or more LOANs. (f) The (min, max) constraints would be changed as follows:

3 Mid 1 Solution: Question 1 : DBMS enables users to create and maintain a database. A foreign key is a referential constraint between two tables. It identifies a column or a set of columns in one table that refers to a set of columns in another table. Referential integrity constraint is specified between two relations and is used to maintain the consistency among tuples in the two relations. Question 2 : The schema is: Person(ssn, name, address) Car(license, state, model, make, year, owner) Car.owner foreign key to Person.ssn Claim(claimId, description, policy) ** Note: This is for 3-way relationship version. For weak entity version, Item.date is also a key field. Item(ssn, license, state, claimid, date, amount)

4 Item.ssn foreign key to Person.ssn Item.claim foreign key to Claim.claimId Item.license and Item.state foreign key to Car.license and Car.state Payment(claimId, date, ssn, amount) Payment.ssn foreign key to Person.ssn Payment.claimId foreign key to Claim.claimId Note the primary key of payment depends on your assumptions. You could make it have an auto-number or some other system generated id in which case it is: Payment(id, ssn, claimid, date, amount) You could make Payment a weak entity dependent on claim id and use id or date as PPK: Payment(id, ssn, claimid, date, amount) OR Payment(ssn, claimid, date, amount) In all cases, there still is a foreign key on ssn and on claimid. Question 3: 1. What are the names of students enrolled in CS380? name( csc380=code(student enrolledin)) 2. Which subjects is Yazeed taking? code( name=yazeed(student enrolledin)) 3. Who teaches CSC 380? lecturer( code=csc380(subject)) 4. What are the names of students in both CSC 380 and CSC 383? name( code=csc380(student enrolledin)) name( code=csc383(student enrolledin))

5 CSC 380 Introduction to Database Solution: Midterm 2 Exercise 1: First Normal Form (1NF): Remove all repeating groups. Make a separate table for each set of related attributes, and give each table a primary key Second Normal Form (2NF): Remove partial dependencies. Eliminate redundant data. If an attribute depends on part of a multi-part(concatenated) key, remove it to a separate table. (assuming E-phone & B-Phone belong to instructor? If they belong to student, them should go to student. Assume, based on your original example, registration date, total fees and fees paid are applied to the student as a whole, not for each course. They should belong to student) STUDENT_COURSE (Student-ID+ Course-ID, Days/Time, Room/Bldg, Instructor, E-Phone, B-Phone ) STUDENT (Student-ID, S-Name, HomeAddr, Advisor, Ofc-Phone, RegisDate, TotalFees, FeesPaid ) COURSE (Course-ID, HoursCredit) Third Normal Form (3NF): Remove transitive dependencies. Eliminate columns not dependent on the primary key. If attributes do not contribute to a description of a key, move them to a separate table. STUDENT-COURSE (Student-ID + Course-ID [fk], Days/Time, Room/Bldg, Instructor[fk] ) SECTION(Course-ID[fk] + Days/Time, Room/Bldg, Instructor[fk] ) STUDENT (Student-ID, S-Name, HomeAddr, Advisor[fk], RegisDate, TotalFees, FeesPaid ) COURSE (Course-ID, HoursCredit ) ADVISOR (Advisor, Ofc-Phone) INSTRUCTOR (Instructor, E-Phone, B-Phone )

6 Exercise 3: SQL Queries: a/ Print title and price of all DVDs in the category Comedy, which cost less than 25 SR. Sort the output by the price (lowest price first). SELECT TITLE, PRICE FROM DVD WHERE CATEGORY = Comedy AND PRICE < 25 ORDER BY PRICE b/ Print number and title of all films (DVDs) that have an English audio track and got 5 stars from the user sb. SELECT E.NO, TITLE FROM EVALUATION E, AUDIOTRACK A, DVD D WHERE D.NO = E.NO AND E.NO = A.NO AND UID = sb AND LANGUAGE = English AND STARS = 5 c/ Print the title of all DVDs with an audio track in English and in Spanisch (both languages on the same DVD). SELECT TITLE FROM DVD D, AUDIOTRACK X, AUDIOTRACK Y WHERE X.NO = Y.NO AND D.NO = X.NO AND X.LANGUAGE = Spanisch AND Y.LANGUAGE = English d/ Which DVDs have only an Arabic audio track? Print the title of all such DVDs. SELECT TITLE FROM DVD D WHERE NO NOT IN (SELECT NO FROM AUDIOTRACK WHERE LANGUAGE <> arabic ) e/ Print for each DVD that was evaluated by at least two customers the title, the category, and the average evaluation (number of stars). The output column for the average evaluation should have the name GRADE. SELECT TITLE, CATEGORY, AVG(STARS) AS GRADE FROM DVD D, EVALUATION E WHERE D.NO = E.NO GROUP BY D.NO, TITLE, CATEGORY HAVING COUNT(*) >= 2 SQL CREATE TABLE: CREATE TABLE EVALUATION( NO NUMERIC(5) NOT NULL REFERENCES DVD, UID VARCHAR(20) NOT NULL, STARS NUMERIC(1) NOT NULL, TEXT VARCHAR(2000) NOT NULL, PRIMARY KEY(NO, UID), CONSTRAINT STARS_VALID CHECK(STARS BETWEEN 1 AND 5))

7 King Saud University College of Computer and Information Sciences Computer Science Department CSC380: Introduction to Database Instructor: Dr. Kamal Haouam Midterm: 2 Sunday: 11/02/1432 (16/01/2011) Time: 90mn Exercise 1: Given the following relation, expressed as: REGISTRATION CARD (Student-ID, S-Name, HomeAddr, Advisor, Ofc-Phone, {Course-ID, Days/Time, HoursCredit, Room/Bldg, Instructor}, E-Phone, B-Phone, RegisDate,TotalFees, FeesPaid) Construct the 1NF, 2NF, AND 3NF. Exercise 2: Given the following relation, expressed as (City, E#, EN, Skill,S, Age) with the typical data shown below, construct the 2NF. Show the answer in the notational form. City E# EN Skill S Age Riyadh 3 Fahed Dammam 4 Naef Dammam 2 Saoud Dammam 3 Fahed Riyadh 7 Bader Madinah 2 Saoud Exercise 3: An online shop for DVDs (video films) uses the following three tables: The first table contains the most important data of the DVDs. Each DVD has a unique number. The database does not contain any null values. DVD NO TITLE CATEGORY PRICE 1 Snow White Cartoon New Shots! Part 2 Comedy Fire Tongs Comedy Spaceballs Comedy In contrast to VHS video tapes, DVDs often contain several audio tracks in different languages. The second table contains this information. NO is a foreign key that refers to DVD.

8 AUDIOTRACK NO LANGUAGE 1 Arabic 1 English 2 Arabic 2 English 2 Spanish 3 Arabic 4 Arabic 4 English 4 French 4 Italian Finally, there is a table with evaluations of the DVDs by customers or users of the website. A user can rate a DVD by giving between one and five stars. NO is again a foreign key that refers to the table DVD. EVALUATION NO UID STARS TEXT 1 Sb 4 Sweet 1 Nina 3 Nice 1 Lisa 5 I watched it already 50 times. 2 Sb 4 funny 3 Sb 3 funny, but picture and sound quality not good. 4 Sb 5 Very funny 4 Nina 3 Well, Ok Questions:( SQL Queries) a) Print title and price of all DVDs in the category Comedy, which cost less than 25 SR. Sort the output by the price (lowest price first). In the example, the query result b) Print number and title of all films (DVDs) that have an English audio track and got 5 stars from the user sb. c) Print the title of all DVDs with an audio track in English and in Spanish (both languages on the same DVD). d) Which DVDs have only an Arabic audio track? Print the title of all such DVDs. e) Print for each DVD that was evaluated by at least two customers the title, the category, and the average evaluation (number of stars). The output column for the average evaluation should have the name GRADE. Questions: (SQL CREATE TABLE) Write a CREATE TABLE statement for the table EVALUATION. Declare the usual constraints (keys, foreign keys, NOT NULL). Use a CHECK-constraint to ensure that the attribute STARS can only take the values 1, 2, 3, 4, 5. The attribute NO is a decimal number of up to five digits. UID is a string up to length 20. TEXT is a string of maximal length Null values are not allowed in any column.

9 CSC380 Fall 2010 Questions Homework SQL Due date : January 11, 2011 Use the Mesri s database, found in my account, to answer the following questions: 1. Retrieve the name of male employees who were born before the year Retrieve the supervisor name for employees living at Houston and working at a department located at the same town. 3. List the different dependent relationships. 4. Retrieve the SSN of employees that do not work for any project controlled by department number 4. Explain: a) A natural join between works_on and project with a qualification dnum<>5 is not enough (expl: essn= ). b) Explain that we take employee and not works_on because an employee who does not have a project at all will be selected. 5. Retrieve the name of each employee who works on all projects controlled by department 5 (explain how the SQL will proceed to execute this statement) 6. For each employee, retrieve the name of his or her immediate supervisor. 7. For each department which it is assigned more than two employees, list the department number, the department name, the number of employees assigned and the average salary. 8. Create a view called project_summary, wich lists for each project the project number, the project name, the number of employees, and the minimum and maximum salary.

10 King Saud University College of Computer and Information Sciences Computer Science Department CSC380: Introduction to Database Instructor: Dr. Kamal Haouam Midterm: 1 Wednesday: 9/1/1432 (15/12/2010) Time: 90mn Question 1 : What is the main functionality of a DBMS? What is a foreign key constraint? Why are such constraints important? What is referential integrity? Given two relation schemas R(A1,A2) and S(A2,A3), define a relational algebra expression which is the equivalent of R JOIN S using only operations from the following list: union, difference, Cartesian product, projection, selection, renaming. Question 2 : The Tawuniya insurance company agrees to pay you to design and implement a database based on the following information: 1. A Person is identified by social security number. The person name and address must be recorded. 2. Cars are identified by license plate. For each car, the model, make, and year is recorded. 3. For each claim, the claim id, policy and description must be recorded. The claim id identifies a claim uniquely. 4. A car is owned by a person. 5. A policy holder itemizes elements of a claim by relating a car, a person, and a claim with a date and amount. 6. Multiple payments may be made from a claim to the person involved in the claim with values for amount and date of payment. Draw the ER diagram for this database. Map your ER diagram into a relational schema (show your keys and foreign keys).

11 Question 3 : Give the following queries in the relational algebra using the relational schema given above, that is student(id, name) enrolledin(id, code) subject(code, lecturer) 1. What are the names of students enrolled in CSC380? 2. Which subjects is Yazeed taking? 3. Who teaches CSC380? 4. What are the names of students in both CSC380 and CSC383? 5. What are the names of students taking a subject taught by Kamal? 6. Count the number of students enrolled in CSC380. Solution: Question 1 : DBMS enables users to create and maintain a database. A foreign key is a referential constraint between two tables. It identifies a column or a set of columns in one table that refers to a set of columns in another table. Referential integrity constraint is specified between two relations and is used to maintain the consistency among tuples in the two relations. Question 2 :

12 The schema is: Person(ssn, name, address) Car(license, state, model, make, year, owner) Car.owner foreign key to Person.ssn Claim(claimId, description, policy) ** Note: This is for 3-way relationship version. For weak entity version, Item.date is also a key field. Item(ssn, license, state, claimid, date, amount) Item.ssn foreign key to Person.ssn Item.claim foreign key to Claim.claimId Item.license and Item.state foreign key to Car.license and Car.state Payment(claimId, date, ssn, amount) Payment.ssn foreign key to Person.ssn Payment.claimId foreign key to Claim.claimId Note the primary key of payment depends on your assumptions. You could make it have an auto-number or some other system generated id in which case it is: Payment(id, ssn, claimid, date, amount) You could make Payment a weak entity dependent on claim id and use id or date as PPK: Payment(id, ssn, claimid, date, amount) OR Payment(ssn, claimid, date, amount) In all cases, there still is a foreign key on ssn and on claimid.

13 CSC380 Fall 2010 Tutorial 4 Solution THE RELATIONAL DATA MODEL AND RELATIONAL DATABASE CONSTRAINTS Exercise1: The schema of this question has the following four foreign keys: 1. the attribute SSN of relation ENROLL that references relation STUDENT, 2. the attribute Course# in relation ENROLL that references relation COURSE, 3. the attribute Course# in relation BOOK_ADOPTION that references relation COURSE, and 4. the attribute Book_ISBN of relation BOOK_ADOPTION that references relation TEXT. Exercise2: Answers: (a) No constraint violations. (b) Violates referential integrity because DNUM=2 and there is no tuple in the DEPARTMENT relation with DNUMBER=2. We may enforce the constraint by: (i) rejecting the insertion of the new PROJECT tuple, (ii) changing the value of DNUM in the new PROJECT tuple to an existing DNUMBER value in the DEPARTMENT relation, or (iii) inserting a new DEPARTMENT tuple with DNUMBER=2. (c) Violates both the key constraint and referential integrity. Violates the key constraint because there already exists a DEPARTMENT tuple with DNUMBER=4. We may enforce this constraint by: (i) rejecting the insertion, or (ii) changing the value of DNUMBER in the new DEPARTMENT tuple to a value that does not violate the key constraint. Violates referential integrity because MGRSSN=' ' and there is no tuple in the EMPLOYEE relation with SSN=' '. We may enforce the constraint by: (i) rejecting the insertion, (ii) changing the value of MGRSSN to an existing SSN value in EMPLOYEE, or (iii) inserting a new EMPLOYEE tuple with SSN=' '.

14 (d) Violates both the entity integrity and referential integrity. Violates entity integrity because PNO, which is part of the primary key of WORKS_ON, is null. We may enforce this constraint by: (i) rejecting the insertion, or (ii) changing the value of PNO in the new WORKS_ON tuple to a value of PNUMBER that exists in the PROJECT relation. Violates referential integrity because ESSN=' ' and there is no tuple in the EMPLOYEE relation with SSN=' '. We may enforce the constraint by: (i) rejecting the insertion, (ii) changing the value of ESSN to an existing SSN value in EMPLOYEE, or (iii) inserting a new EMPLOYEE tuple with SSN=' '. (e) No constraint violations. (f) No constraint violations. (g) Violates referential integrity because several tuples exist in the WORKS_ON, DEPENDENT, DEPARTMENT, and EMPLOYEE relations that reference the tuple being deleted from EMPLOYEE. We may enforce the constraint by: (i) rejecting the deletion, or (ii) deleting all tuples in the WORKS_ON, DEPENDENT, DEPARTMENT, and EMPLOYEE relations whose values for ESSN, ESSN, MGRSSN, and SUPERSSN, respectively, is equal to' '. (h) Violates referential integrity because two tuples exist in the WORKS_ON relations that reference the tuple being deleted from PROJECT. We may enforce the constraint by: (i) rejecting the deletion, or (ii) deleting the tuples in the WORKS_ON relation whose value for PNO=1 (the value for the primary key PNUMBER for the tuple being deleted from PROJECT). (i) No constraint violations. (j) Violates referential integrity because the new value of SUPERSSN=' ' and there is no tuple in the EMPLOYEE relation with SSN=' '. We may enforce the constraint by: (i) rejecting the deletion, or (ii) inserting a new EMPLOYEE tuple with SSN=' '. (k) No constraint violations.

15 CSC380 Fall 2010 Homework SQL Use the Mesri s database, found in my account, to answer the following questions: 1. Retrieve the name of male employees who were born before the year 1938 Select fname,lname,minit From employe Where sex= M and bdate<to_date( 01-jan-1938 ); 2. Retrieve the supervisor name for employees living at Houston and working at a department located at the same town. 3. List the different dependent relationships. Select E2.fname, E2.minit,E2.lname From employee E1, employee E2, dept_location Where E2.dno=dnumber and E1.superssn=E2.ssn; Dlocation= Houston and E1.address like %Houston% ; Select distinct relationship From dependent; 4. Retrieve the SSN of employees that do not work for any project controlled by department number 4. Select ssn From employee Where ssn not in (select essn from works_on, project where pnumber=pno and dnum=4); 5. Retrieve the name of each employee who works on all projects controlled by department 5 (explain how the SQL will proceed to execute this statement) select Fname, lname from employee where not exists (select * from works_on B, project where pno=pnumber and dnum=5 and not exists (select * from works_on C where B.pno=C.pno and C.essn=ssn)); 1

16 6. For each employee, retrieve the name of his or her immediate supervisor. Select E1.SSN, E2.fname,E2.minit,E2.lname From employee E1, employee E2 Where E1.superssn=e2.ssn(+); 7. For each department which it is assigned more than two employees, list the department number, the department name, the number of employees assigned and the average salary. Select dnumber, dname, count(*), avg(salary) From department, employee Where dno=dnumber Group by dnumber, dname Having count(*)>2; 8. Create a view called project_summary, wich lists for each project the project number, the project name, the number of employees, and the minimum and maximum salary. Create view project_summary (pnumber, pname, nb_empl, min_sal, max_sal) as Select pnumber, pname, count(*), min(salary), max(salary) From employee, works_on, project Where pno=pnumber and Essn=ssn Group by pnumber,pname. 2

### CSC 443 Data Base Management Systems. Basic SQL

CSC 443 Data Base Management Systems Lecture 6 SQL As A Data Definition Language Basic SQL SQL language Considered one of the major reasons for the commercial success of relational databases SQL Structured

### Relational Schema. CS 4700/6700 A Sample of Small Database Design Using Microsoft Access

CS 4700/6700 A Sample of Small Database Design Using Microsoft Access Company relational database schema from the textbook (Fundamentals of Database systems, 6 th Edition, by Ramez Elmasri and Shamkant

### Chapter 8. SQL-99: SchemaDefinition, Constraints, and Queries and Views

Chapter 8 SQL-99: SchemaDefinition, Constraints, and Queries and Views Data Definition, Constraints, and Schema Changes Used to CREATE, DROP, and ALTER the descriptions of the tables (relations) of a database

### CHAPTER 8: SQL-99: SCHEMA DEFINITION, BASIC CONSTRAINTS, AND QUERIES

Chapter 8: SQL-99: Schema Definition, Basic Constraints, and Queries 1 CHAPTER 8: SQL-99: SCHEMA DEFINITION, BASIC CONSTRAINTS, AND QUERIES Answers to Selected Exercises 8. 7 Consider the database shown

### New York University Computer Science Department Courant Institute of Mathematical Sciences

New York University Computer Science Department Courant Institute of Mathematical Sciences Homework #5 Solutions Course Title: Database Systems Instructor: Jean-Claude Franchitti Course Number: CSCI-GA.2433-001

### ER & EER to Relational Mapping. Chapter 9 1

ER & EER to Relational Mapping Chapter 9 1 Figure 3.2 ER schema diagram for the company database. Fname Minit Lname Number Name Address N 1 WORKS_FOR Name Locations Sex Salary Ssn Bdate EMPLOYEE NumberOfEmployees

### Introduction to SQL: Data Retrieving

Introduction to SQL: Data Retrieving Ruslan Fomkin Databasdesign för Ingenjörer 1056F Structured Query Language (SQL) History: SEQUEL (Structured English QUery Language), earlier 70 s, IBM Research SQL

### Part A: Data Definition Language (DDL) Schema and Catalog CREAT TABLE. Referential Triggered Actions. CSC 742 Database Management Systems

CSC 74 Database Management Systems Topic #0: SQL Part A: Data Definition Language (DDL) Spring 00 CSC 74: DBMS by Dr. Peng Ning Spring 00 CSC 74: DBMS by Dr. Peng Ning Schema and Catalog Schema A collection

### Lab Assignment 0. 1. Creating a Relational Database Schema from ER Diagram, Populating the Database and Querying over the database with SQL

SS Chung Lab Assignment 0 1. Creating a Relational Database Schema from ER Diagram, Populating the Database and Querying over the database with SQL 1. Creating the COMPANY database schema using SQL (DDL)

### SQL Nested & Complex Queries. CS 377: Database Systems

SQL Nested & Complex Queries CS 377: Database Systems Recap: Basic SQL Retrieval Query A SQL query can consist of several clauses, but only SELECT and FROM are mandatory SELECT FROM

### CHAPTER 3: DATA MODELING USING THE ENTITY-RELATIONSHIP MODEL

Chapter 3: Data Modeling Using the Entity-Relationship Model 1 CHAPTER 3: DATA MODELING USING THE ENTITY-RELATIONSHIP MODEL Answers to Selected Exercises 3.16 Consider the following set of requirements

### Part 4: Database Language - SQL

Part 4: Database Language - SQL Junping Sun Database Systems 4-1 Database Languages and Implementation Data Model Data Model = Data Schema + Database Operations + Constraints Database Languages such as

### Lab Manual. Database Systems COT-313 & Database Management Systems Lab IT-216

Lab Manual Database Systems COT-313 & Database Management Systems Lab IT-216 Lab Instructions Several practicals / programs? Whether an experiment contains one or several practicals /programs One practical

### Summary on Chapter 4 Basic SQL

Summary on Chapter 4 Basic SQL SQL Features Basic SQL DDL o Includes the CREATE statements o Has a comprehensive set of SQL data types o Can specify key, referential integrity, and other constraints Basic

### Exercise 1: Relational Model

Exercise 1: Relational Model 1. Consider the relational database of next relational schema with 3 relations. What are the best possible primary keys in each relation? employ(person_name, street, city)

### SQL-99: Schema Definition, Basic Constraints, and Queries

8 SQL-99: Schema Definition, Basic Constraints, and Queries The SQL language may be considered one of the major reasons for the success of relational databases in the commercial world. Because it became

### CSC 443 Fall 2011 Dr. R. M. Siegfried. Answers to Assignment #1

Answers to Assignment #1 1.14. Consider the Database below: If the name of the 'CS' (Computer Science) Department changes to 'CSSE' (Computer Science and Software Engineering) Department and the corresponding

### CIS 631 Database Management Systems Sample Final Exam

CIS 631 Database Management Systems Sample Final Exam 1. (25 points) Match the items from the left column with those in the right and place the letters in the empty slots. k 1. Single-level index files

### 10CS54: DATABASE MANAGEMENT SYSTEM

CS54: DATABASE MANAGEMENT SYSTEM QUESTION BANK Chapter 1: Introduction to Database Systems Objective: Databases and data base system have become an essential component of everyday life in modern society.

### Database Design. Marta Jakubowska-Sobczak IT/ADC based on slides prepared by Paula Figueiredo, IT/DB

Marta Jakubowska-Sobczak IT/ADC based on slides prepared by Paula Figueiredo, IT/DB Outline Database concepts Conceptual Design Logical Design Communicating with the RDBMS 2 Some concepts Database: an

### CS 338 Join, Aggregate and Group SQL Queries

CS 338 Join, Aggregate and Group SQL Queries Bojana Bislimovska Winter 2016 Outline SQL joins Aggregate functions in SQL Grouping in SQL HAVING clause SQL Joins Specifies a table resulting from a join

### New York University Computer Science Department Courant Institute of Mathematical Sciences

New York University Computer Science Department Courant Institute of Mathematical Sciences Course Title: Database Systems Course Number: CSCIGA.2433-001 Instructor: Jean-Claude Franchitti Session: 1 Assignment

### Database Implementation: SQL Data Definition Language

Database Systems Unit 5 Database Implementation: SQL Data Definition Language Learning Goals In this unit you will learn how to transfer a logical data model into a physical database, how to extend or

### The Structured Query Language. De facto standard used to interact with relational DB management systems Two major branches

CSI 2132 Tutorial 6 The Structured Query Language (SQL) The Structured Query Language De facto standard used to interact with relational DB management systems Two major branches DDL (Data Definition Language)

### Examine the structure of the EMPLOYEES table: EMPLOYEE_ID NUMBER Primary Key FIRST_NAME VARCHAR2(25) LAST_NAME VARCHAR2(25)

Examine the structure of the EMPLOYEES table: EMPLOYEE_ID NUMBER Primary Key FIRST_NAME VARCHAR2(25) LAST_NAME VARCHAR2(25) Which three statements inserts a row into the table? A. INSERT INTO employees

### The Relational Algebra

The Relational Algebra Relational set operators: The data in relational tables are of limited value unless the data can be manipulated to generate useful information. Relational Algebra defines the theoretical

### Lecture 6. SQL, Logical DB Design

Lecture 6 SQL, Logical DB Design Relational Query Languages A major strength of the relational model: supports simple, powerful querying of data. Queries can be written intuitively, and the DBMS is responsible

### CPS352 Database Systems: Design Project

CPS352 Database Systems: Design Project Purpose: Due: To give you experience with designing and implementing a database to model a real domain Various milestones due as shown in the syllabus Requirements

### Question 1. Relational Data Model [17 marks] Question 2. SQL and Relational Algebra [31 marks]

EXAMINATIONS 2005 MID-YEAR COMP 302 Database Systems Time allowed: Instructions: 3 Hours Answer all questions. Make sure that your answers are clear and to the point. Write your answers in the spaces provided.

### The Relational Model. Why Study the Relational Model? Relational Database: Definitions. Chapter 3

The Relational Model Chapter 3 Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 Why Study the Relational Model? Most widely used model. Vendors: IBM, Informix, Microsoft, Oracle, Sybase,

### The Relational Data Model and Relational Database Constraints

The Relational Data Model and Relational Database Constraints Chapter Outline Relational Model Concepts Relational Model Constraints and Relational Database Schemas Update Operations and Dealing with Constraint

### SQL Simple Queries. Chapter 3.1 V3.0. Copyright @ Napier University Dr Gordon Russell

SQL Simple Queries Chapter 3.1 V3.0 Copyright @ Napier University Dr Gordon Russell Introduction SQL is the Structured Query Language It is used to interact with the DBMS SQL can Create Schemas in the

### CS2Bh: Current Technologies. Introduction to XML and Relational Databases. The Relational Model. The relational model

CS2Bh: Current Technologies Introduction to XML and Relational Databases Spring 2005 The Relational Model CS2 Spring 2005 (LN6) 1 The relational model Proposed by Codd in 1970. It is the dominant data

### Review: Participation Constraints

Review: Participation Constraints Does every department have a manager? If so, this is a participation constraint: the participation of Departments in Manages is said to be total (vs. partial). Every did

### LiTH, Tekniska högskolan vid Linköpings universitet 1(7) IDA, Institutionen för datavetenskap Juha Takkinen 2007-05-24

LiTH, Tekniska högskolan vid Linköpings universitet 1(7) IDA, Institutionen för datavetenskap Juha Takkinen 2007-05-24 1. A database schema is a. the state of the db b. a description of the db using a

### 1. SELECT DISTINCT f.fname FROM Faculty f, Class c WHERE f.fid = c.fid AND c.room = LWSN1106

Database schema: Department(deptid, dname, location) Student(snum, sname, deptid, slevel, age) Faculty(fid, fname, deptid) Class(cname, time, room, fid) Enrolled(snum, cname) SQL queries: 1. Get the names

### More SQL: Assertions, Views, and Programming Techniques

9 More SQL: Assertions, Views, and Programming Techniques In the previous chapter, we described several aspects of the SQL language, the standard for relational databases. We described the SQL statements

### COMP 5138 Relational Database Management Systems. Week 5 : Basic SQL. Today s Agenda. Overview. Basic SQL Queries. Joins Queries

COMP 5138 Relational Database Management Systems Week 5 : Basic COMP5138 "Relational Database Managment Systems" J. Davis 2006 5-1 Today s Agenda Overview Basic Queries Joins Queries Aggregate Functions

### Chapter 9, More SQL: Assertions, Views, and Programming Techniques

Chapter 9, More SQL: Assertions, Views, and Programming Techniques 9.2 Embedded SQL SQL statements can be embedded in a general purpose programming language, such as C, C++, COBOL,... 9.2.1 Retrieving

### The Relational Model. Why Study the Relational Model? Relational Database: Definitions

The Relational Model Database Management Systems, R. Ramakrishnan and J. Gehrke 1 Why Study the Relational Model? Most widely used model. Vendors: IBM, Microsoft, Oracle, Sybase, etc. Legacy systems in

### b. Examine the following histories. Draw their serialization graph and identify which of them is serializable given reasons.

SELECTED SOLUTIONS TO THE EVISION EECISES: 1. In the following questions the operations are as follows rn() transaction n reads data item, wn () transaction n writes data item, cn transactions n commits,

### Figure 14.1 Simplified version of the

Figure. Simplified version of the COMPANY relational database schema. EMPLOYEE f.k. ENAME SSN BDATE ADDRESS DNUMBER DEPARTMENT f.k. DNAME DNUMBER DMGRSSN DEPT_LOCATIONS f.k. DNUMBER DLOCATION PROJECT f.k.

### The Relational Model. Ramakrishnan&Gehrke, Chapter 3 CS4320 1

The Relational Model Ramakrishnan&Gehrke, Chapter 3 CS4320 1 Why Study the Relational Model? Most widely used model. Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc. Legacy systems in older models

### Databases in Engineering / Lab-1 (MS-Access/SQL)

COVER PAGE Databases in Engineering / Lab-1 (MS-Access/SQL) ITU - Geomatics 2014 2015 Fall 1 Table of Contents COVER PAGE... 0 1. INTRODUCTION... 3 1.1 Fundamentals... 3 1.2 How To Create a Database File

### Graham Kemp (telephone 772 54 11, room 6475 EDIT) The examiner will visit the exam room at 15:00 and 17:00.

CHALMERS UNIVERSITY OF TECHNOLOGY Department of Computer Science and Engineering Examination in Databases, TDA357/DIT620 Tuesday 17 December 2013, 14:00-18:00 Examiner: Results: Exam review: Grades: Graham

### SQL NULL s, Constraints, Triggers

CS145 Lecture Notes #9 SQL NULL s, Constraints, Triggers Example schema: CREATE TABLE Student (SID INTEGER PRIMARY KEY, name CHAR(30), age INTEGER, GPA FLOAT); CREATE TABLE Take (SID INTEGER, CID CHAR(10),

### Introduction to SQL (3.1-3.4)

CSL 451 Introduction to Database Systems Introduction to SQL (3.1-3.4) Department of Computer Science and Engineering Indian Institute of Technology Ropar Narayanan (CK) Chatapuram Krishnan! Summary Parts

### 3. Relational Model and Relational Algebra

ECS-165A WQ 11 36 3. Relational Model and Relational Algebra Contents Fundamental Concepts of the Relational Model Integrity Constraints Translation ER schema Relational Database Schema Relational Algebra

### Introduction to normalization. Introduction to normalization

Introduction to normalization Lecture 4 Instructor Anna Sidorova Agenda Presentation Review of relational models, in class exersise Introduction to normalization In-class exercises Discussion of HW2 1

### Data Modeling. Database Systems: The Complete Book Ch. 4.1-4.5, 7.1-7.4

Data Modeling Database Systems: The Complete Book Ch. 4.1-4.5, 7.1-7.4 Data Modeling Schema: The structure of the data Structured Data: Relational, XML-DTD, etc Unstructured Data: CSV, JSON But where does

### Intermediate SQL C H A P T E R4. Practice Exercises. 4.1 Write the following queries in SQL:

C H A P T E R4 Intermediate SQL Practice Exercises 4.1 Write the following queries in SQL: a. Display a list of all instructors, showing their ID, name, and the number of sections that they have taught.

### Database Design and the E-R Model

C H A P T E R 7 Database Design and the E-R Model Practice Exercises 7.1 Answer: The E-R diagram is shown in Figure 7.1. Payments are modeled as weak entities since they are related to a specific policy.

### Databases What the Specification Says

Databases What the Specification Says Describe flat files and relational databases, explaining the differences between them; Design a simple relational database to the third normal form (3NF), using entityrelationship

### IT2305 Database Systems I (Compulsory)

Database Systems I (Compulsory) INTRODUCTION This is one of the 4 modules designed for Semester 2 of Bachelor of Information Technology Degree program. CREDITS: 04 LEARNING OUTCOMES On completion of this

### CS 7700 Transaction Design for Microsoft Access Database with JDBC

CS 7700 Transaction Design for Microsoft Access Database with JDBC Purpose The purpose of this tutorial is to introduce the process of developing transactions for a Microsoft Access Database with Java

### Using Multiple Operations. Implementing Table Operations Using Structured Query Language (SQL)

Copyright 2000-2001, University of Washington Using Multiple Operations Implementing Table Operations Using Structured Query Language (SQL) The implementation of table operations in relational database

### Structured Query Language (SQL)

Objectives of SQL Structured Query Language (SQL) o Ideally, database language should allow user to: create the database and relation structures; perform insertion, modification, deletion of data from

### The Entity-Relationship Model

The Entity-Relationship Model 221 After completing this chapter, you should be able to explain the three phases of database design, Why are multiple phases useful? evaluate the significance of the Entity-Relationship

### Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification

Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 Outline More Complex SQL Retrieval Queries

### Information Systems SQL. Nikolaj Popov

Information Systems SQL Nikolaj Popov Research Institute for Symbolic Computation Johannes Kepler University of Linz, Austria popov@risc.uni-linz.ac.at Outline SQL Table Creation Populating and Modifying

### Introduction to SQL C H A P T E R3. Exercises

C H A P T E R3 Introduction to SQL Exercises 3.1 Write the following queries in SQL, using the university schema. (We suggest you actually run these queries on a database, using the sample data that we

### EECS 647: Introduction to Database Systems

EECS 647: Introduction to Database Systems Instructor: Luke Huan Spring 2013 Administrative Take home background survey is due this coming Friday The grader of this course is Ms. Xiaoli Li and her email

### COURSE CODE: CIT 844 COURSE TITLE: ADVANCED DATABASE MANAGEMENT SYSTEM

NATIONAL OPEN UNIVERSITY OF NIGERIA COURSE CODE: CIT 844 COURSE TITLE: ADVANCED DATABASE MANAGEMENT SYSTEM CIT 844 ADVANCED DATABASE MANAGEMENT SYSTEM COURSE GIUDE ADVANCED DATABASE MANAGEMENT SYSTEM Course

### VIEWS virtual relation data duplication consistency problems

VIEWS A virtual relation that is defined from other preexisting relations Called the defining relations of the view A view supports multiple user perspectives on the database corresponding to different

### There are five fields or columns, with names and types as shown above.

3 THE RELATIONAL MODEL Exercise 3.1 Define the following terms: relation schema, relational database schema, domain, attribute, attribute domain, relation instance, relation cardinality, andrelation degree.

### SQL Data Definition. Database Systems Lecture 5 Natasha Alechina

Database Systems Lecture 5 Natasha Alechina In This Lecture SQL The SQL language SQL, the relational model, and E/R diagrams CREATE TABLE Columns Primary Keys Foreign Keys For more information Connolly

### IT2304: Database Systems 1 (DBS 1)

: Database Systems 1 (DBS 1) (Compulsory) 1. OUTLINE OF SYLLABUS Topic Minimum number of hours Introduction to DBMS 07 Relational Data Model 03 Data manipulation using Relational Algebra 06 Data manipulation

### Bridge from Entity Relationship modeling to creating SQL databases, tables, & relations

1 Topics for this week: 1. Good Design 2. Functional Dependencies 3. Normalization Readings for this week: 1. E&N, Ch. 10.1-10.6; 12.2 2. Quickstart, Ch. 3 3. Complete the tutorial at http://sqlcourse2.com/

### SQL - QUICK GUIDE. Allows users to access data in relational database management systems.

http://www.tutorialspoint.com/sql/sql-quick-guide.htm SQL - QUICK GUIDE Copyright tutorialspoint.com What is SQL? SQL is Structured Query Language, which is a computer language for storing, manipulating

### CHAPTER 3. Relational Database Management System: Oracle. 3.1 COMPANY Database

45 CHAPTER 3 Relational Database Management System: Oracle This chapter introduces the student to the basic utilities used to interact with Oracle DBMS. The chapter also introduces the student to programming

### Answer Key. UNIVERSITY OF CALIFORNIA College of Engineering Department of EECS, Computer Science Division

Answer Key UNIVERSITY OF CALIFORNIA College of Engineering Department of EECS, Computer Science Division CS186 Fall 2003 Eben Haber Midterm Midterm Exam: Introduction to Database Systems This exam has

### Introduction to Microsoft Jet SQL

Introduction to Microsoft Jet SQL Microsoft Jet SQL is a relational database language based on the SQL 1989 standard of the American Standards Institute (ANSI). Microsoft Jet SQL contains two kinds of

### Fundamentals of Database Systems. Laboratory Manual 1. Rajshekhar Sunderraman. Georgia State University. August 2010

Fundamentals of Database Systems Laboratory Manual 1 Rajshekhar Sunderraman Georgia State University August 2010 1 To accompany Elmasri and Navathe, Fundamentals of Database Systems, 6 th Edition, Addison-Wesley,

### Entity-Relationship Model

UNIT -2 Entity-Relationship Model Introduction to ER Model ER model is represents real world situations using concepts, which are commonly used by people. It allows defining a representation of the real

### Requirement Analysis & Conceptual Database Design. Problem analysis Entity Relationship notation Integrity constraints Generalization

Requirement Analysis & Conceptual Database Design Problem analysis Entity Relationship notation Integrity constraints Generalization Introduction: Lifecycle Requirement analysis -> Text Conceptual Design

### DATABASE NORMALIZATION

DATABASE NORMALIZATION Normalization: process of efficiently organizing data in the DB. RELATIONS (attributes grouped together) Accurate representation of data, relationships and constraints. Goal: - Eliminate

### Database Design--from E-R Diagram to SQL Statement

Database Design--from E-R Diagram to SQL Statement Problem Set 3 In problem set 3 * you will: Create an entity-relationship diagram for a database Construct a simple database design Input records into

### 4. SQL. Contents. Example Database. CUSTOMERS(FName, LName, CAddress, Account) PRODUCTS(Prodname, Category) SUPPLIERS(SName, SAddress, Chain)

ECS-165A WQ 11 66 4. SQL Contents Basic Queries in SQL (select statement) Set Operations on Relations Nested Queries Null Values Aggregate Functions and Grouping Data Definition Language Constructs Insert,

### Database Design. Database Design I: The Entity-Relationship Model. Entity Type (con t) Chapter 4. Entity: an object that is involved in the enterprise

Database Design Database Design I: The Entity-Relationship Model Chapter 4 Goal: specification of database schema Methodology: Use E-R R model to get a high-level graphical view of essential components

### Data Modeling: Part 1. Entity Relationship (ER) Model

Data Modeling: Part 1 Entity Relationship (ER) Model MBA 8473 1 Cognitive Objectives (Module 2) 32. Explain the three-step process of data-driven information system (IS) development 33. Examine the purpose

### CSCI-GA.2433-001 Database Systems Lecture 7: Schema Refinement and Normalization

CSCI-GA.2433-001 Database Systems Lecture 7: Schema Refinement and Normalization Mohamed Zahran (aka Z) mzahran@cs.nyu.edu http://www.mzahran.com View 1 View 2 View 3 Conceptual Schema At that point we

### Databasesystemer, forår 2005 IT Universitetet i København. Forelæsning 3: Business rules, constraints & triggers. 3. marts 2005

Databasesystemer, forår 2005 IT Universitetet i København Forelæsning 3: Business rules, constraints & triggers. 3. marts 2005 Forelæser: Rasmus Pagh Today s lecture Constraints and triggers Uniqueness

### featuring data privacy Andres Avelino Campos Sainz A Project submitted in partial fulfillment of the requirements for the degree of

An application to provide an interface to a mysql database located in the cloud featuring data privacy by Andres Avelino Campos Sainz A Project submitted in partial fulfillment of the requirements for

### CMU - SCS 15-415/15-615 Database Applications Spring 2013, C. Faloutsos Homework 1: E.R. + Formal Q.L. Deadline: 1:30pm on Tuesday, 2/5/2013

CMU - SCS 15-415/15-615 Database Applications Spring 2013, C. Faloutsos Homework 1: E.R. + Formal Q.L. Deadline: 1:30pm on Tuesday, 2/5/2013 Reminders - IMPORTANT: Like all homeworks, it has to be done

### Databases and BigData

Eduardo Cunha de Almeida eduardo.almeida@uni.lu Outline of the course Introduction Database Systems (E. Almeida) Distributed Hash Tables and P2P (C. Cassagnes) NewSQL (D. Kim and J. Meira) NoSQL (D. Kim)

### Chapter 6: Integrity Constraints

Chapter 6: Integrity Constraints Domain Constraints Referential Integrity Assertions Triggers Functional Dependencies Database Systems Concepts 6.1 Silberschatz, Korth and Sudarshan c 1997 Domain Constraints

### Scheme G. Sample Test Paper-I

Scheme G Sample Test Paper-I Course Name : Computer Engineering Group Course Code : CO/CM/IF/CD/CW Marks : 25 Hours: 1 Hrs. Q.1 Attempt Any THREE. 09 Marks a) List any six applications of DBMS. b) Define

### Database Management Systems. Chapter 1

Database Management Systems Chapter 1 Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 2 What Is a Database/DBMS? A very large, integrated collection of data. Models real-world scenarios

### CMPT 354 Database Systems. Simon Fraser University Summer 2016. Instructor: Oliver Schulte

CMPT 354 Database Systems Simon Fraser University Summer 2016 Instructor: Oliver Schulte Assignment 1: Entity-Relationship Modeling. The Relational Model. MS SQL Server. Instructions: Check the instructions

### Chapter 1: Introduction. Database Management System (DBMS) University Database Example

This image cannot currently be displayed. Chapter 1: Introduction Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Database Management System (DBMS) DBMS contains information

### Define terms Write single and multiple table SQL queries Write noncorrelated and correlated subqueries Define and use three types of joins

Chapter 7 Advanced SQL 1 Define terms Objectives Write single and multiple table SQL queries Write noncorrelated and correlated subqueries Define and use three types of joins 2 Nested Queries (Subqueries)

### Relational Algebra. Module 3, Lecture 1. Database Management Systems, R. Ramakrishnan 1

Relational Algebra Module 3, Lecture 1 Database Management Systems, R. Ramakrishnan 1 Relational Query Languages Query languages: Allow manipulation and retrieval of data from a database. Relational model

### Review Entity-Relationship Diagrams and the Relational Model. Data Models. Review. Why Study the Relational Model? Steps in Database Design

Review Entity-Relationship Diagrams and the Relational Model CS 186, Fall 2007, Lecture 2 R & G, Chaps. 2&3 Why use a DBMS? OS provides RAM and disk A relationship, I think, is like a shark, you know?

### Chapter 10. Functional Dependencies and Normalization for Relational Databases

Chapter 10 Functional Dependencies and Normalization for Relational Databases Chapter Outline 1 Informal Design Guidelines for Relational Databases 1.1Semantics of the Relation Attributes 1.2 Redundant

### University of Massachusetts Amherst Department of Computer Science Prof. Yanlei Diao

University of Massachusetts Amherst Department of Computer Science Prof. Yanlei Diao CMPSCI 445 Midterm Practice Questions NAME: LOGIN: Write all of your answers directly on this paper. Be sure to clearly

### Chapter 3. Data Modeling Using the Entity-Relationship (ER) Model

Chapter 3 Data Modeling Using the Entity-Relationship (ER) Model Chapter Outline Overview of Database Design Process Example Database Application (COMPANY) ER Model Concepts Entities and Attributes Entity

### Chapter 10 Functional Dependencies and Normalization for Relational Databases

Chapter 10 Functional Dependencies and Normalization for Relational Databases Copyright 2004 Pearson Education, Inc. Chapter Outline 1 Informal Design Guidelines for Relational Databases 1.1Semantics of

### Database Design Overview. Conceptual Design ER Model. Entities and Entity Sets. Entity Set Representation. Keys

Database Design Overview Conceptual Design. The Entity-Relationship (ER) Model CS430/630 Lecture 12 Conceptual design The Entity-Relationship (ER) Model, UML High-level, close to human thinking Semantic