Dorm Name PK Occupancy Dorm Name PK Occupancy HighResDorm StartDate HighResDorm StartDate LowResDorm StartDate WaterSensorID WaterOnLineDate ElecSensorID.

Slides:



Advertisements
Similar presentations
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,
Advertisements

Complex Integrity Constraints in SQL. Constraints over a Single Table Table Constraint: Create TABLE Sailors (sid INTEGER, sname CHAR(10), rating INTEGER,
MySQL. To start go to Login details: login: labuser password:macimd15 – There.
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’s Data Definition Language (DDL) n DDL statements define, modify and remove objects from data dictionary tables maintained by the DBMS n Whenever you.
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),
CIT 381 Data Types - data types - create table statement - constraints.
1 Relational Model. 2 Relational Database: Definitions  Relational database: a set of relations  Relation: made up of 2 parts: – Instance : a table,
Murali Mani SQL DDL and Oracle utilities. Murali Mani Datatypes in SQL INT (or) INTEGER FLOAT (or) REAL DECIMAL (n, m) CHAR (n) VARCHAR (n) DATE, TIME.
Creating Tables, Defining Constraints Rose-Hulman Institute of Technology Curt Clifton.
SQL Keys and Constraints Justin Maksim. Key Declaration Key constraint defined within the CREATE TABLE command Key can be declared using either the PRIMARY.
Mapping of N:M Relationships PERSON-ID TITLE PERSON-NAME DATE-OF-BIRTH PERSON-ID PROJECT-ID HOURS-SPENT PROJECT-ID END-DATE START-DATE E-R Diagram PERSON.
5 Chapter 5 Structured Query Language (SQL1) Revision.
SQL DDL constraints Restrictions on the columns and tables 1SQL DDL Constraints.
Database Management System LICT 3011 Eyad H. Elshami.
Midterm 1 Concepts Relational Algebra (DB4) SQL Querying and updating (DB5) Constraints and Triggers (DB11) Unified Modeling Language (DB9) Relational.
DATABASES AND SQL. Introduction Relation: Relation means table(data is arranged in rows and columns) Domain : A domain is a pool of values appearing in.
For Project 1, Deliverable 4, you will add referential integrity (FOREIGN KEY) constraints to existing tables, as well as composing general assertions.
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.
SQL Data Definition Language (DDL) Using Microsoft SQL Server 1SDL Data Definition Language (DDL)
Slide 1 Chapter 7 – Part 1 Data Definition Language & Data Manipulation Language.
Chapter 5: Part 1: DDL STRUCTURED QUERY LANGUAGE (SQL)
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.
SQL: DDL John Ortiz Cs.utsa.edu.
SQL Basics. 5/27/2016Chapter 32 of 19 Naming SQL commands are NOT case sensitive SQL commands are NOT case sensitive But user identifier names ARE case.
The Relational Model1 ER-to-Relational Mapping and Views.
SQL: DDL. SQL Statements DDL - data definition language –Defining and modifying data structures (metadata): database, tables, views, etc. DML - data manipulation.
Database Management System Quiz 1. A company needs to store information about: the employees identified by EmpNo, Name, Salary and Phone; departments.
Recap of SQL Lab no 8 Advance Database Management System.
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.
MySQL More… 1. More on SQL In MySQL, the Information Schema is the “Catalog” in the SQL standard SQL has three components: Data definition Data manipulation.
CS 3630 Database Design and Implementation. Database Schema Branch (Bno…) Staff (Sno…Bno) Owner (Ono…) PropertyForRent (Pno…Ono) Renter (Rno…) Viewing.
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,
Introduction to Database System Adisak Intana Lecturer Chapter 7 : Data Integrity.
CREATE TABLE CREATE TABLE statement is used for creating relations Each column is described with three parts: column name, data type, and optional constraints.
SQL introduction 2013.
© 2002 by Prentice Hall 1 David M. Kroenke Database Processing Eighth Edition Chapter 9 Structured Query Language.
Sql DDL queries CS 260 Database Systems.
1 SQL Insert Update Delete Create table Alter table.
CS34311 The Relational Model. cs34312 Why Relational Model? Currently the most widely used Vendors: Oracle, Microsoft, IBM Older models still used IBM’s.
CREATE TABLE ARTIST ( ArtistID int NOT NULL IDENTITY (1,1), Namechar(25) NOT NULL, TEXT ERROR Nationality char (30) NULL, Birthdate numeric (4,0) NULL,
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.
Murali Mani Constraints. Murali Mani Keys: Primary keys and unique CREATE TABLE Student ( sNum int, sName varchar (20), dept char (2), CONSTRAINT key.
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.
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.
MS SQL Create Table Cust USE jxc00 GO CREATE TABLE cust ( cust_id smallint IDENTITY(1,1) NOT NULL, cust_name char(10)
Study group exercises In attendance: 1. Suppose you have a relation P ( A, B, C, D, E, F ), with functional dependencies (FDs) A  B, BCD  E, E  F Suppose.
Database Management System
SQL: Schema Definition and Constraints Chapter 6 week 6
CS 3630 Database Design and Implementation
Referential Integrity MySQL
Minggu 5, Pertemuan 9 SQL: Data Definition
For student, require values for name and address.
These are slides from Dr. Phil Cannata’s Class
Session - 6 Sequence - 1 SQL: The Structured Query Language:
Database Design: Relational Model
Instructor: Samia arshad
SQLDeveloper Data Modeler - Logical Model
Presentation transcript:

Dorm Name PK Occupancy Dorm Name PK Occupancy HighResDorm StartDate HighResDorm StartDate LowResDorm StartDate WaterSensorID WaterOnLineDate ElecSensorID ElecOnLineDate LowResDorm StartDate WaterSensorID WaterOnLineDate ElecSensorID ElecOnLineDate Floor FloorNum PK Occupancy Floor FloorNum PK Occupancy HRWaterSensor SensorID PK OnLineDate Units HRWaterSensor SensorID PK OnLineDate Units HRElecSensor SensorID PK OnLineDate Units HRElecSensor SensorID PK OnLineDate Units HREReading Date PK Time PK Value HREReading Date PK Time PK Value LRWReading Date PK Time PK Value LRWReading Date PK Time PK Value LREReading Date PK Time PK Value LREReading Date PK Time PK Value AmbientValue Date PK Time PK Temp Light AmbientValue Date PK Time PK Temp Light Observer NetworkID PK Observer NetworkID PK FloorWebPage FWPageID PK Date Time FloorWebPage FWPageID PK Date Time DormWebPage DWPageID PK Date Time DormWebPage DWPageID PK Date Time LocatedAt PK Would accept 1..1 instead of or in addition to Would accept 0..1 instead of or in addition to 0..* Complete coverage No overlap Consistent with table definitions, but think it should be with change to tables too Consistent with table definitions, but think it should be with change to tables too PK 0..* PK 0..* PK 0..* 1..* PK HRWReading Date PK Time PK Value HRWReading Date PK Time PK Value 0..* Undoubtedly, there are other UML diagrams consistent with the table and assertion definitions that were distributed as the “gold standard”, but they are not likely to deviate much from this and still be consistent

Dorm Name PK Occupancy Dorm Name PK Occupancy HighResDorm StartDate HighResDorm StartDate Floor FloorNum PK Occupancy Floor FloorNum PK Occupancy AmbientValue Date PK Time PK Temp Light AmbientValue Date PK Time PK Temp Light Observer NetworkID PK Observer NetworkID PK FloorWebPage FWPageID PK Date Time FloorWebPage FWPageID PK Date Time DormWebPage DWPageID PK Date Time DormWebPage DWPageID PK Date Time LocatedAt 0..* PK 0..* CREATE TABLE Observer ( NetworkID CHAR(20), DormName VARCHAR(35), PRIMARY KEY (NetworkID), FOREIGN KEY (DormName) REFERENCES Dorm ON DELETE CASCADE ON UPDATE CASCADE); CREATE TABLE Dorm ( DormName VARCHAR(35), MaxOccupancy SMALLINT, PRIMARY KEY (DormName)); CREATE TABLE AmbientValues ( AmbientReadingsDate DATE, AmbientReadingsTime TIME, AmbientTemp TINYINT NOT NULL, AmbientLight CHAR(2), PRIMARY KEY (AmbientReadingsDate, AmbientReadingsTime)); CREATE TABLE HighResDorm ( DormName VARCHAR(35), StartDate DATE, PRIMARY KEY (DormName), FOREIGN KEY (DormName) REFERENCES Dorm ON DELETE CASCADE ON UPDATE CASCADE); CREATE TABLE Floor ( DormName VARCHAR(35), FloorNum TINYINT, MaxOccupancy SMALLINT, PRIMARY KEY (DormName, FloorNum), FOREIGN KEY (DormName) REFERENCES HighResDorm ON DELETE CASCADE ON UPDATE CASCADE); CREATE TABLE FloorWebPage ( DormName VARCHAR(35), FloorNum TINYINT, FWPageID INTEGER, CreateDate DATE NOT NULL, CreateTime TIME NOT NULL, ObserverNetworkID CHAR(20) NOT NULL, PRIMARY KEY (FWPageID), FOREIGN KEY (ObserverNetworkID) REFERENCES Observer (NetworkID), ON DELETE NO ATION ON UPDATE CASCADE, FOREIGN KEY (DormName, FloorNum) REFERENCES Floor ON DELETE NO ACTION ON UPDATE CASCADE ); DormName VARCHAR(35), FloorNum TINYINT, DormName VARCHAR(35) NOT NULL, FloorNum TINYINT NOT NULL, OR CREATE TABLE DormWebPage ( DWPageID INTEGER, CreateDate DATE NOT NULL, CreateTime TIME NOT NULL, ObserverNetworkID CHAR(20) NOT NULL, DormName VARCHAR(35) NOT NULL, PRIMARY KEY (DWPageID), FOREIGN KEY (ObserverNetworkID) REFERENCES Observer (NetworkID) ON DELETE NO ACTION ON UPDATE CASCADE, FOREIGN KEY (DormName) REFERENCES Dorm ON DELETE NO ACTION ON UPDATE CASCADE );

Dorm Name PK Occupancy Dorm Name PK Occupancy HighResDorm StartDate HighResDorm StartDate LowResDorm StartDate WaterSensorID WaterOnLineDate ElecSensorID ElecOnLineDate LowResDorm StartDate WaterSensorID WaterOnLineDate ElecSensorID ElecOnLineDate Floor FloorNum PK Occupancy Floor FloorNum PK Occupancy HRWaterSensor SensorID PK OnLineDate Units HRWaterSensor SensorID PK OnLineDate Units LRWReading Date PK Time PK Value LRWReading Date PK Time PK Value LREReading Date PK Time PK Value LREReading Date PK Time PK Value PK 0..* PK 0..* PK 0..* PK HRWReading Date PK Time PK Value HRWReading Date PK Time PK Value 0..* CREATE TABLE LowResDorm ( DormName VARCHAR(35), StartDate DATE, LRElecSensorID INTEGER NOT NULL, UNIQUE(LRElecSensorID), /*UNIQUE not inferable from UML */ LRElecSensorOnLineDate DATE, LRWaterSensorOnLineDate DATE, LRWaterSensorID INTEGER, PRIMARY KEY (DormName), FOREIGN KEY (DormName) REFERENCES Dorm ON DELETE CASCADE ON UPDATE CASCADE ); CREATE TABLE HRWSensor ( DormName VARCHAR(35) NOT NULL, FloorNum TINYINT NOT NULL, HRWaterSensorID INTEGER, HRWaterSensorOnLineDate DATE, PRIMARY KEY (HRWaterSensorID), FOREIGN KEY (DormName, FloorNum) REFERENCES Floor ON DELETE CASCADE ON UPDATE CASCADE ); CREATE TABLE HRWReading ( HRWaterSensorID INTEGER, HRWReadingDate DATE, HRWReadingTime TIME, HRWValue INTEGER NOT NULL, PRIMARY KEY (HRWaterSensorID, HRWReadingDate, HRWReadingTime), FOREIGN KEY (HRWaterSensorID) REFERENCES HRWaterSensor ON DELETE NO ACTION ON UPDATE CASCADE); CREATE TABLE LREReading ( DormName VARCHAR(35), LREReadingDate DATE, LREReadingTime TIME, LREValue INTEGER NOT NULL, PRIMARY KEY (DormName, LREReadingDate, LREReadingTime), FOREIGN KEY (DormName) REFERENCES LowResDorm ON DELETE NO ACTION ON UPDATE CASCADE); CREATE TABLE LRWReading ( DormName VARCHAR(35), LRWReadingDate DATE, LRWReadingTime TIME, LRWValue INTEGER NOT NULL, PRIMARY KEY (DormName, LRWReadingDate, LRWReadingTime) FOREIGN KEY (DormName) REFERENCES LowResDorm ON DELETE NO ACTION ON UPDATE CASCADE

Dorm Name PK Occupancy Dorm Name PK Occupancy HighResDorm StartDate HighResDorm StartDate LowResDorm StartDate WaterSensorID WaterOnLineDate ElecSensorID ElecOnLineDate LowResDorm StartDate WaterSensorID WaterOnLineDate ElecSensorID ElecOnLineDate Floor FloorNum PK Occupancy Floor FloorNum PK Occupancy HRElecSensor SensorID PK OnLineDate Units HRElecSensor SensorID PK OnLineDate Units HREReading Date PK Time PK Value HREReading Date PK Time PK Value PK 0..* 1..* 0..* No overlap CREATE ASSERTION CompleteCoverOverLowAndHighRes ( CHECK (NOT EXISTS (SELECT D.DormName FROM Dorm D EXCEPT SELECT LRD.DormName FROM LowResDorm LRD) EXCEPT SELECT HRD.DormName FROM HighResDorm HRD ) ); Complete coverage CREATE ASSERTION FloorParticipatesHRElecSensor ( CHECK (NOT EXISTS (SELECT * FROM Floor F WHERE (F.DormName, F.FloorNum) NOT IN (SELECT HRES.DormName, HRES.FloorNum FROM HRElecSensor HRES))); CREATE TABLE HRElecSensor ( DormName VARCHAR(35) NOT NULL, FloorNum TINYINT NOT NULL, HRElecSensorID INTEGER, HRElecSensorOnLineDate DATE, PRIMARY KEY (HRElecSensorID), FOREIGN KEY (DormName, FloorNum) REFERENCES Floor ON DELETE CASCADE ON UPDATE CASCADE ); CREATE ASSERTION NoOverlapBetweenHighAndLowRes ( CHECK (NOT EXISTS (SELECT * FROM LowResDorm L, HighResDorm H WHERE L.DormName=H.DormName)); CREATE TABLE HREReading ( HRElecSensorID INTEGER, HREReadingDate DATE, HREReadingTime TIME, HREValue INTEGER NOT NULL, PRIMARY KEY (HRElecSensorID, HREReadingDate, HREReadingTime), FOREIGN KEY (HRElecSensorID) REFERENCES HRElecSensor ON DELETE NO ACTION ON UPDATE CASCADE);