For Project 1, Deliverable 4, you will add referential integrity (FOREIGN KEY) constraints to existing tables, as well as composing general assertions.

Slides:



Advertisements
Similar presentations
Data Definition and Integrity Constraints
Advertisements

1 Constraints, Triggers and Active Databases Chapter 9.
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.
SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
SQL Constraints and Triggers
Day 3 - Basics of MySQL What is MySQL What is MySQL How to make basic tables How to make basic tables Simple MySQL commands. Simple MySQL commands.
Cs3431 Constraints Sections 6.1 – 6.5. cs3431 Example CREATE TABLE Student ( sNum int, sName varchar (20), prof int, CONSTRAINT pk PRIMARY KEY (snum),
THE RELATIONAL DATABASE MODEL & THE DATABASE DEVELOPMENT PROCESS Fact of the Week: According to a Gartner study in ‘06, Microsoft SQL server had the highest.
Monday, 08 June 2015Dr. Mohamed Osman1 What is Database Administration A high level function (technical Function) that is responsible for ► physical DB.
Maintenance Modifying the data –Add records –Delete records –Update records Modifying the design –Add fields into tables –Remove fields from a table –Change.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Basic (Flat) Relational Model.
1 Translation of ER-diagram into Relational Schema Prof. Sin-Min Lee Department of Computer Science.
SPRING 2004CENG 3521 The Relational Model Chapter 3.
1 Relational Model. 2 Relational Database: Definitions  Relational database: a set of relations  Relation: made up of 2 parts: – Instance : a table,
SQL Keys and Constraints Justin Maksim. Key Declaration Key constraint defined within the CREATE TABLE command Key can be declared using either the PRIMARY.
Database Design Concepts INFO1408 Term 2 week 1 Data validation and Referential integrity.
SQL DDL constraints Restrictions on the columns and tables 1SQL DDL Constraints.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 157 Database Systems I SQL Constraints and Triggers.
Database Systems Lecture 5 Natasha Alechina
The Relational Model These slides are based on the slides of your text book.
The Relational Model. Review Why use a DBMS? OS provides RAM and disk.
Assume the following relational schema covering vehicle ownership data (forgive lack of key, or assume that all attributes form the key, for now). Name.
SQL Data Definition (CB Chapter 6) CPSC 356 Database Ellen Walker Hiram College (Includes figures from Database Systems by Connolly & Begg, © Addison Wesley.
Chapter 9 Integrity. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.9-2 Topics in this Chapter Predicates and Propositions Internal vs.
Lecture 7 Integrity & Veracity UFCE8K-15-M: Data Management.
DBMS Spring 2014 Database Integrity Sources: Security in Computing, Pfleeger and Pfleeger, Prentice Hall, 2003 Lecture Slides, CSE6243, MSU, Rayford B.
For Project 1, Deliverable 4, you will add referential integrity (FOREIGN KEY) constraints to existing tables, as well as composing general assertions.
1 The Relational Model. 2 Why Study the Relational Model? v Most widely used model. – Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc. v “Legacy.
For Project 1, Deliverable 3, you will be stepping back from your designs and studying mine. You can edit this file and include your answers here. 120.
FALL 2004CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
Intro to SQL| MIS 2502  Spacing not relevant › BUT… no spaces in an attribute name or table name  Oracle commands keywords, table names, and attribute.
For Project 1, Deliverable 4, you will add referential integrity (FOREIGN KEY) constraints to existing tables, as well as composing general assertions.
Creating Tables and Inserting Records -- Not easy to edit! -- check constraints! Create table test1 ( C1 char(5) primary key, C2 Varchar2(15) not null.
IST 210 Constraints and Triggers. IST Constraints and Triggers Constraint: relationship among data elements DBMS should enforce the constraints.
Dec 8, 2003Murali Mani Constraints B term 2004: lecture 15.
Chapter 9 Constraints. Chapter Objectives  Explain the purpose of constraints in a table  Distinguish among PRIMARY KEY, FOREIGN KEY, UNIQUE, CHECK,
Oracle 11g: SQL Chapter 4 Constraints.
Chapter 4 Constraints Oracle 10g: SQL. Oracle 10g: SQL 2 Objectives Explain the purpose of constraints in a table Distinguish among PRIMARY KEY, FOREIGN.
Constraints and Triggers. What’s IC? Integrity Constraints define the valid states of SQL-data by constraining the values in the base tables. –Restrictions.
Module Coordinator Tan Szu Tak School of Information and Communication Technology, Politeknik Brunei Semester
Chapter 9 Logical Database Design : Mapping ER Model To Tables.
1 CS 430 Database Theory Winter 2005 Lecture 4: Relational Model.
CSE314 Database Systems Lecture 3 The Relational Data Model and Relational Database Constraints Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
The Relational Database Model & The Database Development Process
The relational model A data model (in general) : Integrated collection of concepts for describing data (data requirements). Relational model was introduced.
Constraints Lesson 8. Skills Matrix Constraints Domain Integrity: A domain refers to a column in a table. Domain integrity includes data types, rules,
DATA AND SCHEMA MODIFICATIONS CHAPTERS 4,5 (6/E) CHAPTER 8 (5/E) 1.
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.
©Silberschatz, Korth and Sudarshan1 Structured Query Language (SQL) Data Definition Language Domains Integrity Constraints.
CS34311 The Relational Model. cs34312 Why Relational Model? Currently the most widely used Vendors: Oracle, Microsoft, IBM Older models still used IBM’s.
SQL constrains and keys. SORTED RESULTS Sort the results by a specified criterion SELECT columns FROM tables WHERE predicates ORDER BY column ASC/DESC;
Dorm Name PK Occupancy Dorm Name PK Occupancy HighResDorm StartDate HighResDorm StartDate LowResDorm StartDate WaterSensorID WaterOnLineDate ElecSensorID.
Murali Mani Constraints. Murali Mani Keys: Primary keys and unique CREATE TABLE Student ( sNum int, sName varchar (20), dept char (2), CONSTRAINT key.
Constraints Advanced Database Systems Dr. AlaaEddin Almabhouh.
CDT/1 Creating data tables and Referential Integrity Objective –To learn about the data constraints supported by SQL2 –To be able to relate tables together.
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.
CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
1 Constraints and Triggers in SQL. 2 Constraints are conditions that must hold on all valid relation instances SQL2 provides a variety of techniques for.
Constraints and Triggers
Database Keys and Constraints
Foreign Keys Local and Global Constraints Triggers
CPSC-310 Database Systems
The Relational Model Relational Data Model
Constraints.
SQL-1 Week 8-9.
Database Design: Relational Model
SQL – Constraints & Triggers
CPSC-608 Database Systems
Presentation transcript:

For Project 1, Deliverable 4, you will add referential integrity (FOREIGN KEY) constraints to existing tables, as well as composing general assertions. TEAM ID: TEAM Members: 1) Copy over your comments /*... */ from Deliverable 3, for each table definition, revised in accordance with my comments on the Deliverable 3 answer. 2) Add FOREIGN KEY constraints to the all table definitions for which they are appropriate. Explicitely show (i.e., no reliance on default settings) all ON DELETE and ON UPDATE actions (use the SQLite options at Explain why you chose these settings in C-style comments (/*... */) immediately after the table definition in which the foreign key constraint is declared. 3) Add any UNIQUE, and other attribute, tuple, and table constraints that you think appropriate. Explain why you chose these UNIQUE declarations in C-style comments (/*... */) immediately after the table definition in which the UNIQUE constraint is declared. 4) For each blank ASSERTION definition, fill in the definition to enforce the conditions as sepecified in header comments. /* Observer associates computer network identifiers (e.g., IP addresses) with campus dormitories. DormName can be NULL, thus allowing easy recording of off-campus (or otherwise non-dorm) network identifiers of virtual visitors to dorm web-based electricity and water usage summaries. */ CREATE TABLE Observer ( NetworkID CHAR(20), DormName VARCHAR(35), PRIMARY KEY (NetworkID) );

/* ADD FOREIGN KEY CONSTRAINT(s) TO THIS TABLE DEFINITION */ /* A record of visits to a Dorm’s (often assembled, on demand) Webpage, which displays statistics on electricity and water usage */ CREATE TABLE DormWebPage ( DWPageID INTEGER, CreateDate DATE NOT NULL, /* NOT NULL indicates field cannot be NULL in any record */ CreateTime TIME NOT NULL, ObserverNetworkID CHAR(20) NOT NULL, /* Corresponds to a NetworkID in Observer */ DormName VARCHAR(35) NOT NULL, /* Corresponds to a DormName in Dorm */ PRIMARY KEY (DWPageID) ); /* Comment here */ CREATE TABLE Dorm ( DormName VARCHAR(35), MaxOccupancy SMALLINT, PRIMARY KEY (DormName) );

/* A table of time-stamped outdoor temperatures (required) and light conditions (optional) */ CREATE TABLE AmbientValues ( AmbientReadingsDate DATE, AmbientReadingsTime TIME, AmbientTemp TINYINT NOT NULL, AmbientLight CHAR(2), PRIMARY KEY (AmbientReadingsDate, AmbientReadingsTime) ); /* ADD FOREIGN KEY CONSTRAINT(s) TO THIS TABLE DEFINITION */ /* Comment here */ CREATE TABLE HighResDorm ( DormName VARCHAR(35), /* Corresponds to a DormName in Dorm */ StartDate DATE, /* Date at which it became a HighResDorm */ PRIMARY KEY (DormName) );

/* ADD FOREIGN KEY CONSTRAINT(s) TO THIS TABLE DEFINITION */ /* Comment here */ CREATE TABLE LowResDorm ( DormName VARCHAR(35), /* Corresponds to a DormName in Dorm */ StartDate DATE, /* Date at which it became a LowResDorm */ LRElecSensorID INTEGER NOT NULL, UNIQUE(LRElecSensorID), /* UNIQUE indicates a key; typically implies NOT NULL */ LRElecSensorOnLineDate DATE, LRWaterSensorOnLineDate DATE, LRWaterSensorID INTEGER, PRIMARY KEY (DormName) ); // This assertion insures that there is no Dorm in LowResDorm that is also in HighResDorm, // and vice versa. The assertion is checked each time there is a change in LowResDorm or // HighResDorm. If the assertion evaluates to TRUE, then there is no violation of the constraint. CREATE ASSERTION NoOverlapBetweenHighAndLowRes ( /* FILL IT IN */ );

/* ADD FOREIGN KEY CONSTRAINT(s) TO THIS TABLE DEFINITION */ /* Comment here */ CREATE TABLE Floor ( DormName VARCHAR(35), /* Corresponds to a DormName in HighResDorm */ FloorNum TINYINT, MaxOccupancy SMALLINT, PRIMARY KEY (DormName, FloorNum) ); /* ADD FOREIGN KEY CONSTRAINT(s) TO THIS TABLE DEFINITION */ /* Comment here */ CREATE TABLE FloorWebPage ( DormName VARCHAR(35), /* Corresponds to DormName in Floor */ FloorNum TINYINT, /* Corresponds to FloorNum in Floor */ FWPageID INTEGER, CreateDate DATE NOT NULL, CreateTime TIME NOT NULL, ObserverNetworkID CHAR(20) NOT NULL, /* Corresponds to NetworkID in Observer */ PRIMARY KEY (FWPageID) );

/* ADD FOREIGN KEY CONSTRAINT(s) TO THIS TABLE DEFINITION */ /* Comment here */ CREATE TABLE HRElecSensor ( DormName VARCHAR(35) NOT NULL, /* Corresponds to DormName in Floor */ FloorNum TINYINT NOT NULL, /* Corresponds to FloorNum in Floor */ HRElecSensorID INTEGER, HRElecSensorOnLineDate DATE, PRIMARY KEY (HRElecSensorID) ); //* ADD FOREIGN KEY CONSTRAINT(s) TO THIS TABLE DEFINITION */ * Comment here */ CREATE TABLE HREReading ( HRElecSensorID INTEGER, /* Corresponds to HRElecSensorID in HRElecSensor */ HREReadingDate DATE, HREReadingTime TIME, HREValue INTEGER NOT NULL, PRIMARY KEY (HRElecSensorID, HREReadingDate, HREReadingTime), );

/* ADD FOREIGN KEY CONSTRAINT(s) TO THIS TABLE DEFINITION */ /* Comment here */ CREATE TABLE HRWSensor ( DormName VARCHAR(35) NOT NULL, /* Corresponds to DormName in Floor */ FloorNum TINYINT NOT NULL, /* Corresponds to FloorNum in Floor */ HRWaterSensorID INTEGER, HRWaterSensorOnLineDate DATE, PRIMARY KEY (HRWaterSensorID) ); /* ADD FOREIGN KEY CONSTRAINT(s) TO THIS TABLE DEFINITION */ /* Comment here */ CREATE TABLE HRWReading ( HRWaterSensorID INTEGER, /* Corresponds to HRWaterSensorID in HRWaterSensor */ HRWReadingDate DATE, HRWReadingTime TIME, HRWValue INTEGER NOT NULL, PRIMARY KEY (HRWaterSensorID, HRWReadingDate, HRWReadingTime) );

/* ADD FOREIGN KEY CONSTRAINT(s) TO THIS TABLE DEFINITION */ /* Comment here */ CREATE TABLE LREReading ( DormName VARCHAR(35), /* Corresponds to DormName in LowResDorm */ LREReadingDate DATE, LREReadingTime TIME, LREValue INTEGER NOT NULL, PRIMARY KEY (DormName, LREReadingDate, LREReadingTime) ); /* ADD FOREIGN KEY CONSTRAINT(s) TO THIS TABLE DEFINITION */ /* Comment here */ CREATE TABLE LRWReading ( DormName VARCHAR(35), /* Corresponds to DormName in LowResDorm */ LRWReadingDate DATE, LRWReadingTime TIME, LRWValue INTEGER NOT NULL, PRIMARY KEY (DormName, LRWReadingDate, LRWReadingTime) );

/* Insure all Dorms are Low Res or High Res; another assertion required to insure no overlap (exclusive or) */ CREATE ASSERTION CompleteCoverOverLowAndHighRes ( /* FILL IT IN */ ); /* Insure that each Floor is associated with at least one electricity sensor */ CREATE ASSERTION FloorParticipatesHRElecSensor ( /* FILL IT IN */ );

Reflect on these questions. You do NOT need to answer and submit them in writing, but they will be topics of discussion. a) If you try to delete a row in Observer that has one or more ‘associated’ entries in DormWebPage, what will happen? b) If you try to delete a Dorm, for which no one has ever looked at (Observed) a DormWebPage for it, what will happen? c) If you try to delete a Dorm, for which there have been one or more recorded views of DormWebPages for it, what will happen? d) How many electricity sensors are associated with a low res dorm (so far as the DB encodes)? And vice versa? e) How many electricity sensors are associated with a high res dorm (so far as the DB encodes)? f) Could the current database design (tables and assertions) support the situation of a low res dorm becoming a high res dorm WITHOUT losing past data from its low res days? If so, explain, and if not, explain what changes to the DB design you might make to support this (high likelihood eventuality) PRIOR to DB implementation. g) How could the DB design be changed to support records of room and plug level measurements of electricity (and perhaps faucet level water readings)?