CSC343: Intro. to Databases1 Tutorial for CSC343 Introduction to Databases Fall 2006 Week 2.

Slides:



Advertisements
Similar presentations
Introduction to Relational Database Systems 1 Lecture 4.
Advertisements

Active database concepts
Relational data integrity
Data Definition and Integrity Constraints
COP4540 Database Management System Midterm Review
ER to Relational Mapping. Logical DB Design: ER to Relational Entity sets to tables. CREATE TABLE Employees (ssn CHAR (11), name CHAR (20), lot INTEGER,
Logical DB Design: ER to Relational Entity sets to tables. Employees ssn name lot CREATE TABLE Employees (ssn CHAR (11), name CHAR (20), lot INTEGER, PRIMARY.
Fundamentals of Database Systems Fourth Edition El Masri & Navathe
The Relational Model Much of the material presented in these slides was developed by Dr. Ramon Lawrence at the University of Iowa.
COP-5725 Practice Exercises
Relational Database. Relational database: a set of relations Relation: made up of 2 parts: − Schema : specifies the name of relations, plus name and type.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 SQL: Queries, Programming, Triggers Chapter 5 Modified by Donghui Zhang.
The Relational Model. Introduction Introduced by Ted Codd at IBM Research in 1970 The relational model represents data in the form of table. Main concept.
SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
Fall 2005 ICS184/EECS116 – Notes 08 1 ICS 184/EECS116: Introduction to Data Management Lecture Note 8 SQL: Structured Query Language -- DDL.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 28 Database Systems I The Relational Data Model.
COP5725 – Principles of Database Management Systems
1 Translation of ER-diagram into Relational Schema Prof. Sin-Min Lee Department of Computer Science.
SPRING 2004CENG 3521 The Relational Model Chapter 3.
The Relational Model 198:541 Rutgers University. Why Study the Relational Model?  Most widely used model. Vendors: IBM, Informix, Microsoft, Oracle,
1 Relational Model. 2 Relational Database: Definitions  Relational database: a set of relations  Relation: made up of 2 parts: – Instance : a table,
1 Data Modeling Yanlei Diao UMass Amherst Feb 1, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
CS 380 Introduction to Database Systems (Chapter 5: The Relational Data Model and Relational Database Constraints)
The Relational Model These slides are based on the slides of your text book.
Relational Data Model, R. Ramakrishnan and J. Gehrke with Dr. Eick’s additions 1 The Relational Model Chapter 3.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
1 The Relational Model Chapter 3. 2 Why Study the Relational Model?  Most widely used model.  Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3 Modified by Donghui Zhang.
1 The Relational Model Chapter 3. 2 Why Study the Relational Model?  Most widely used model  Vendors: IBM, Informix, Microsoft, Oracle, Sybase  Recent.
1 Translation of ER-diagram into Relational Schema Prof. Sin-Min Lee Department of Computer Science.
Chapter 8 Part 1 SQL-99 Schema Definition, Constraints, Queries, and Views.
1 The Relational Model Chapter 3. 2 Why Study the Relational Model?  Most widely used model.  Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc.
1 The Relational Model Chapter 3. 2 Why Study the Relational Model?  Most widely used model.  Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc.
Assignements. CSC343: Intro. to Databases2 Exercise 1 Superkeys: Candidate keys: Primary key:
1 The Relational Model. 2 Why Study the Relational Model? v Most widely used model. – Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc. v “Legacy.
FALL 2004CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
1.1 CAS CS 460/660 Relational Model. 1.2 Review E/R Model: Entities, relationships, attributes Cardinalities: 1:1, 1:n, m:1, m:n Keys: superkeys, candidate.
The Relational Model1 ER-to-Relational Mapping and Views.
Advanced Database CS-426 Week 1 - Introduction. Database Management System DBMS contains information about a particular enterprise Collection of interrelated.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
CREATE TABLE CREATE TABLE statement is used for creating relations Each column is described with three parts: column name, data type, and optional constraints.
CMPT 258 Database Systems The Relationship Model PartII (Chapter 3)
COMP3030 Database Management System Final Review
Week 8-9 SQL-1. SQL Components: DDL, DCL, & DML SQL is a very large and powerful language, but every type of SQL statement falls within one of three main.
The Relational Model Jianlin Feng School of Software SUN YAT-SEN UNIVERSITY.
CS34311 The Relational Model. cs34312 Why Relational Model? Currently the most widely used Vendors: Oracle, Microsoft, IBM Older models still used IBM’s.
COP-5725 Practice Exercises
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
Lecture 03 Constraints. Example Schema CONSTRAINTS.
Mapping E/R to RM, R. Ramakrishnan and J. Gehrke with Dr. Eick’s additions 1 Mapping E/R Diagrams to Relational Database Schemas Second Half of Chapter.
Chapter 3 The Relational Model. Objectives u Terminology of relational model. u How tables are used to represent data. u Connection between mathematical.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
LECTURE TWO Introduction to Databases: Data models Relational database concepts Introduction to DDL & DML.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
1 CS122A: Introduction to Data Management Lecture #4 (E-R  Relational Translation) Instructor: Chen Li.
1 The Relational Model Chapter 3. 2 Why Study the Relational Model?  Most widely used model.  Multi-billion dollar industry, $15+ bill in  Vendors:
CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
Assignements.
SQL – Part 2.
SQL: Schema Definition and Constraints Chapter 6 week 6
Translation of ER-diagram into Relational Schema
SQL-1 Week 8-9.
Session - 6 Sequence - 1 SQL: The Structured Query Language:
ISC321 Database Systems I Chapter 4: SQL: Data definition, Constraints, and Basic Queries and Updates Fall 2015 Dr. Abdullah Almutairi.
Session - 6 Sequence - 1 SQL: The Structured Query Language:
CS 405G: Introduction to Database Systems
Presentation transcript:

CSC343: Intro. to Databases1 Tutorial for CSC343 Introduction to Databases Fall 2006 Week 2

CSC343: Intro. to Databases2 T.A. and Tutorials Yuan An Tutorials: Week 2, 3, 4, 5, 7, 9, 10, 11, 12, 13 (10 times). Week 6: Postgres SQL by Kiran Gollu. Week 8: Midterm (no tutorial). Some even-numbered questions. Answers for odd-numbered questions: – ion/supporting_material.htm

CSC343: Intro. to Databases3 Exercise E. 3.2 How many distinct tuples are in a relation instance with cardinality 22? Answer: Since a relation is formally defined as, if the cardinality is 22 (i.e., there are ), there must be distinct tuples.

CSC343: Intro. to Databases4 Exercise E. 3.4 What is the difference between a candidate key and the primary key for a given relation? What is a superkey? Answer: The primary key is the selected by the DBA from among the. A candidate key. A superkey is that.

CSC343: Intro. to Databases5 Exercise Superkeys: Candidate keys: Primary key:

CSC343: Intro. to Databases6 Exercise Superkeys: Candidate keys: Primary key:

CSC343: Intro. to Databases7 Exercise Superkeys: Candidate keys: Primary key:

CSC343: Intro. to Databases8 Exercise E. 3.6 What is a foreign key constraint? Why are such constraints important? What is referential integrity? Answer: A foreign key constraint requires that the values on a set X of attributes of a relation R1 must appear as values for of.

CSC343: Intro. to Databases9 Exercise E. 3.6 Answer: Foreign key constraints are important because they provide safeguards for insuring the of data. Referential integrity means all are enforced.

CSC343: Intro. to Databases10 Exercise

CSC343: Intro. to Databases11 Table Definition An SQL table consists of an ordered set of attributes, and a (possibly empty) set of constraints Statement create table defines a relation schema, creating an empty instance. Syntax: create table TableName ( AttributeName Domain [ DefaultValue ] [ Constraints ] {, AttributeName Domain [ DefaultValue ] [ Constraints ] } [ OtherConstraints ] )

CSC343: Intro. to Databases12 Example of create table create table Employee ( RegNo character(6) primary key, FirstName character(20) not null, Surname character(20) not null, Dept character (15) references Department(DeptName) on delete set null on update cascade, Salary numeric(9) default 0, City character(15), unique(Surname,FirstName) )

CSC343: Intro. to Databases13 Example create table Employee ( RegNo char(6), FirstName char(20) not null, Surname char(20) not null, Dept char(15), Salary numeric(9) default 0, City char(15), primary key(RegNo), foreign key(Dept) references Department(DeptName) on delete set null on update cascade, unique(FirstName,Surname) )

CSC343: Intro. to Databases14 Exercise E. 3.8 Answer each of the following questions briefly. The questions are based on the following relational schema: –Emp (eid: integer, ename: string, age: integer, salary: real) –Works (eid: integer, did: integer, pcttime: integer) –Dept (did: integer, dname: string, budget: real, managerid: integer)

CSC343: Intro. to Databases15 Exercise Q1. Give an example of a foreign key constraint that involves the Dept relation. What are the options for enforcing this constraint when a user attempts to delete a Dept tuple?

CSC343: Intro. to Databases16 Exercise A1: CREATE TABLE (,, )

CSC343: Intro. to Databases17 Exercise When a user attempts to delete a Dept tuple, there are four options: 1.Also delete all tuples that refer to it. 2.Disallow the of the Dept tuple if some tuple refers to it. 3.For every tuple that refers to it, set the did field to the did of some. 4.For every tuple that refers to it, set the did field to.

CSC343: Intro. to Databases18 Exercise Q2. Write the SQL statements required to create the preceding relations, including appropriate versions of all primary and foreign key integrity constraints.