Database Modelling. Lecture 4 (b): Database Integrity, Keys & Constraints. Akhtar Ali 10/14/2014 1

Size: px
Start display at page:

Download "Database Modelling. Lecture 4 (b): Database Integrity, Keys & Constraints. Akhtar Ali 10/14/2014 1"

Transcription

1 Database Modelling Lecture 4 (b): Database Integrity, Keys & Constraints Akhtar Ali 10/14/2014 1

2 Learning Objectives 1. To consider Referential Integrity & Foreign Keys 2. To consider Referential Integrity Constraints in SQL 3. To consider Ad Hoc Constraints in principle 4. To consider Ad Hoc Constraints in SQL 5. To consider other aspects of integrity constraints in SQL. 10/14/2014 2

3 Purpose of Referential Integrity To ensure that two different relations are consistent with each other. Example: Consider the previous CAR relation. We know that it does not make sense for an owner in CAR not to be an employee in EMPLOYEE. 10/14/2014 3

4 Consistent Cross-referencing CAR EMPLOYEE RegNo K123 5 ABC W811 6 STA JON 1 7 V771 8 PQ Type Corsa 1.3 Starlet GLi Jaguar XK Volvo S80 Owner E3 E5 2 E1 E6 ENo E3 1 E5 2 E1 3 E6 4 E8 EName Smith 5 Mitchell 6 Robson 7 Blake 8 Jones M-S S 2 M 4 D 6 M 8 W Sal 12, , , , ,000 CAR[Owner] is a subset of EMPLOYEE[ENo] So every CAR Owner attribute value must appear in the EMPLOYEE ENo attribute. So the set of CAR Owner attribute values must be a subset of the EMPLOYEE ENo values. Consistency between a DB s relations is often required. 10/14/2014 4

5 Definition of Referential Integrity CAR EMPLOYEE RegNo K123 5 ABC W811 6 STA JON 1 7 V771 8 PQ Type Corsa 1.3 Starlet GLi J aguar XK Volvo S80 Owner E3 E5 2 E1 E6 ENo E3 1 E5 2 E1 3 E6 4 E8 EName Smith 5 Mitchell 6 Robson 7 Blake 8 Jones M_ S S 2 M 4 D 6 M 8 W Sal 12, , , , ,000 Referenc ing Attribute. Referenc ed Attribute. The values in a referencing attribute must be the same set or a (proper) subset of the values in the referenced attribute. Thus both attributes must be drawn from the same underlying data type. 10/14/2014 5

6 Full Definition Referential integrity can be generalised to apply between two corresponding sets of attributes, where the sets may contain more than one attribute. Hence the full definition is :- The set of n-tuples in the referencing set of n-attributes must be the same set or a (proper) subset of the n-tuples in the referenced set of n-attributes. Thus both sets of n-attributes must be based on the same set of underlying data types. 10/14/2014 6

7 Foreign Keys CAR EMPLOYEE RegNo K123 5 ABC W811 6 STA JON 1 7 V771 8 PQ Type Corsa 1.3 Starl et GLi Jaguar XK Volvo S80 Owner E3 E5 2 E1 E6 ENo E3 1 E5 2 E1 3 E6 4 E8 EName Smith 5 Mitchell 6 Robson 7 Blake 8 Jones M_ S 2 S M 4 D 6 M 8 W Sal 12, , , , ,000 Foreign Key This is a Primary / Candidate Key. The referencing (set of) attribute(s) is called a Foreign Key. The Foreign Key gets its name because traditionally the referenced (set of) attribute(s) is always a candidate key. In SQL, the referenced (set of) attribute(s) must be a primary or alternate key. However this is not logically necessary, and in principle a Foreign Key may reference any (set of) attribute(s) with the same underlying data type(s). 10/14/2014 7

8 Key Overlap A foreign key can occur within a candidate key, or overlap with it. Example: Foreign Key within a Candidate Key SHIPMENT SUPPLIER PNo P1 5 P2 6 P2 7 SNo S1 S1 S2 Qty SNo S1 S2 Details P3 8 S2 7 S3... Candidate Key Foreign Key 10/14/2014 8

9 Self-Referential Integrity A foreign key can reference an attribute(s) in the same relation as itself. Example A manager must also be an employee SUPERVISE Mger E1 E1 E1 E2 E2 E2 E3 Emp E1 E2 E3 E4 E5 E6 E7 Foreign Key Candidate Key 10/14/2014 9

10 Supervise Relation Usually the foreign key is in a different relation to the referenced candidate key, This is not a logical necessity, as the above example demonstrates. The SUPERVISE relation shows which employees each manager supervises. However each manager is an employee, and will be supervised by their own manager. Therefore Mger is a foreign key that references the candidate key Emp. 10/14/

11 Handling the Top A hierarchical management organisation is assumed here. The managing director (with Emp value E1 ) is at the root of the management hierarchy and is not supervised by anyone. How is this absence of his/her manager, i.e. this missing value, to be dealt with? Either: Use a special value to represent the missing manager. Use null; the null would be in the foreign key not the primary/candidate key. State that the managing director s manager is him/herself. 10/14/

12 Further Considerations The link between foreign and candidate keys is asymmetric. It is the foreign key that is dependent on the candidate key for its values, not vice versa. A foreign key can, and often does, have values that are replicated in more than one tuple. The set of foreign key values must be a subset of the candidate key s set of values. 10/14/

13 Missing Foreign Key Values Is it essential that the foreign key always have a candidate key value, or is it permissible for it to be missing? For CAR and EMPLOYEE relations, not every employee may be a car owner. Indeed a foreign key value can be missing, unless it is part of a candidate key. In some cases though e.g. STUDENT:COURSE would expect every student to be on a course. 10/14/

14 SQL Referential Integrity Referential integrity constraints can be named in the same way as primary/alternate key constraints. Foreign Keys are allowed to be NULLs (unless additionally specified not to). A foreign key can be declared for a single attribute in the same sub-statement in which it is assigned its data type, or for one or more attributes in a separate substatement at the end of a Create Table statement. 10/14/

15 SQL Foreign Key Assignment 1 1. Assign a single attribute to be a foreign key in the same substatement in which it is assigned its data type. After the data type, append: References TABLENAME ( AttributeName ) Keyword Insert actual names of table & attribute. 10/14/

16 SQL Foreign Key Assignment 2 2. Assign one or more attributes to a foreign key in a separate sub-statement at the end of a Create Table statement Foreign Key ( AttributeName(s) ) References TABLENAME ( AttributeName(s) ) 10/14/

17 Example of an SQL Foreign Key (1) Give the relation CAR a foreign key, attribute Owner, referencing attribute ENo of EMPLOYEE. Create Table CAR ( RegNo Char(9) Primary Key, Type Varchar2(24), Owner Char(2) References EMPLOYEE( ENo ) ) ; Create Table CAR ( RegNo Char(9) Primary Key, Type Varchar2(24), Owner Char(2), Foreign Key(Owner) References EMPLOYEE( ENo ) ); Two equivalent versions, with no user-assigned constraint name. Both are acceptable in Oracle. 10/14/

18 Example of an SQL Foreign Key (2) Create Table SHIPMENT ( PNo Char(2), SNo Char(2) Constraint FOR_KEY References SUPPLIER (SNo ), Qty Integer, Constraint CAND_KEY Primary Key (Pno, SNo) ); Create Table SHIPMENT ( PNo Char(2), SNo Char(2), Qty Integer, Constraint CAND_KEY Primary Key (Pno, SNo), Constraint FOR_KEY Foreign Key ( SNo ) References SUPPLIER (SNo ) ); Two equivalent versions, with user-assigned constraint names. 10/14/

19 Example of an SQL Foreign Key (3) Ensure that the first row entered is the manager that manages him/herself! (i.e. the root of the hierarchical tree). This is because self-referentiality applies. It prevents any row being put into the table whose employee does not have a manager. Create Table SUPERVISE ( Mger Char(2), Emp Char(2), Constraint CAND_KEY Primary Key (Emp), Constraint FOR_KEY Foreign Key ( Mger ) References SUPERVISE ( Emp ) ); 10/14/

20 Why Ad Hoc Constraints? These are other constraints on values held in a relation. They need to be applied to ensure the database holds accurate data. They usually fall into two classes : To ensure physical reality applies. Example: Weights are always positive. To ensure Business Rules are kept - this reflects the way the organisation works. Example: It is the company policy to only buy cars with an engine capacity of less than 2 litres. 10/14/

21 The Nature of Ad Hoc Constraints In general, an integrity constraint is a limitation on the permissible values that a DB relation can hold. It could be expressed as: IF a tuple appears in a DB relation THEN that tuple satisfies a certain condition. The condition must always be a binary condition, which evaluates to true or false Attribute type, candidate key, and referential integrity constraints are special cases. 10/14/

22 Ad Hoc Constraints in SQL They are applied using the Check option. The format is Check (condition) A whole variety of conditions can be inserted. As with other constraints, ad hoc constraints (Check constraints) can be part of an attribute sub-statement or in a separate sub-statement at the end of the Create Table statement. 10/14/

23 Types of conditions The condition used in the Check must be a binary condition. The conditions are typically comparisons of attribute values. However there is no limit to what may be written in a condition. Conditions may include calculations. They may also consist of several sub-conditions linked together by logical ANDs and ORs; and logical NOT may also be used. 10/14/

24 Example Check Conditions (1) Constraining the values in a relation about products. The check that a price is not zero or a negative may be considered common sense (or a check to avoid corruption?) rather than explicitly a business rule or physical reality check. Constraining the values in a relation about products. Ensu ring Physical Reality Create Table PRODUCT ( Prodno Char( 5 ) Primary Key, Weight Number Check ( Weight > 0 ), Price Number Check ( Price > 0 ), Quantity Number, Constraint Value Check ( Quantity * Price < )); Applying a Business Rule! The Value constraint uses 2 attributes : therefore it cannot appear in the sub-statement of either attribute but must appear in its own sub-statement at the end. Applying a Business Rule about the maximum permissible stock. 10/14/

25 Example Check Conditions (2) Put more complex constraints on the product relation instead. Create Table PRODUCT ( Prodno Char(5) Primary Key, Weight Number Check ( Weight > 0 And Not (Weight > 100) ), Price Number Check ( (Price > 0 And Price < 10) Or (Price > 50 And Price < 95) Or (Price > 250 And Price < 320) ), Quantity Number, Constraint Value Check( Quantity * Price < )); In the revised example above, an upper limit has also been put on weights. Price is now checked to see if it falls into one of three price ranges. 10/14/

26 Multiple Integrity Constraints Although not illustrated yet, it is possible and sometimes desirable in SQL to assign more than one integrity constraint in an attribute substatement. Example : consider a different version of the PRODUCT relation. Create Table PRODUCT ( Prodno Char( 5 ) Pr imary Key, Weight Number Constraint WT_NOT_NULL Not Null Constraint POS_WT Check ( Weight > 0 ) Constraint WT_REF References LIST_WEIGHTS (Wts), Price Number, Quantity Number ); In the above example, the Weight attribute is assigned 4 integrity constraints in one sub-statement : 1. its data type, 2. that it cannot be null, 3. that it must have a positive weight, 4. that its value must occur in the Wts attribute of relation LIST_WEIGHTS (presumably in effect a list of permissible weights). 10/14/

27 SQL Default Values It is possible to specify that an attribute has a default value. This means that : IF a tuple is to be put into a relation AND IF no value is specified for that attribute in the tuple THEN the attribute is given the default value in that tuple. Default values are not integrity constraints but they must satisfy the integrity constraints. SQL syntax for defaults is: Default default_value 10/14/

28 Example Default Value Self evidently, the default value must be chosen so that it does satisfy all the integrity constraints! Example : Create Table EMPLOYEE ( ENo Char(2), Ename Varchar(30), M_S Char(1) Default S Check( M_S In ( S, M, W, D )) ) ; 10/14/

29 SQL Alter Table It can be useful, or even necessary, to alter relations some time after they have been created. SQL provides the Alter Table command for this. Alter Table provides the following ways of changing a relation. Add or drop an attribute; Add or drop an existing integrity constraint; Set or modify a default value for existing attribute. 10/14/

30 Restrict/Cascade When dropping an attribute or constraint there are two options in the statement: Restrict and Cascade. If Restrict is chosen, which is the default, then it will not be dropped if it is referenced by anything else; thus an alternate key attribute will not be dropped if it is referenced by a foreign key. If Cascade is chosen, then anything referencing the dropped item will be dropped as well. 10/14/

31 Example Alter Table Statements DROP TABLE EMP CASCADE CONSTRAINTS; CREATE TABLE EMP ( EMP_NO CHAR(2) CONSTRAINT PKEY_EMP PRIMARY KEY, EMP_NAME CHAR(10), SALARY INTEGER CONSTRAINT MIN_SAL CHECK (SALARY >= 6000) ); ALTER TABLE EMP ADD MARITAL_STATUS CHAR(1) DEFAULT '?' CONSTRAINT MAR_STATS CHECK (MARITAL_STATUS IN ('S', 'M', 'W', 'D', '?')); ALTER TABLE EMP MODIFY MARITAL_STATUS DEFAULT NULL ; /* cannot drop a default, but can set it to null */ ALTER TABLE EMP ADD CONSTRAINT SENSIBLE_SAL CHECK (Salary > 5000 AND Salary < 50000); 10/14/

32 Side effects of DROP TABLE In Oracle 10g / 11g, any table dropped can be restored: It creates a copy of the dropped table in a recycle bin, e.g., DROP TABLE EMP; will create a table in the user s DB: BIN$HCoDqI8ZSEe9zuFgS6irDw==$0 To restore a table use FLASHBACK e.g., FLASHBACK TABLE EMP TO BEFORE DROP; You cannot specifically drop the BIN... table. But you can use PURGE RECYCLEBIN; to clear the bin. To drop a table altogether use: PURGE e.g., DROP TABLE EMP PURGE; 10/14/

Amendments & Transactions

Amendments & Transactions Slide 1 Amendments & Transactions Objectives of the Lecture : To consider amendments to a relation; To consider transactions in SQL. Slide 2 Relational Amendment Strictly speaking, relational amendment

More information

To understand the concept of candidate and primary keys and their application in table creation.

To understand the concept of candidate and primary keys and their application in table creation. CM0719: Database Modelling Seminar 5 (b): Candidate and Primary Keys Exercise Aims: To understand the concept of candidate and primary keys and their application in table creation. Outline of Activity:

More information

Database Modelling. Lecture 5 Part 1: Updating Database 1/6/2015 1

Database Modelling. Lecture 5 Part 1: Updating Database 1/6/2015 1 Database Modelling Lecture 5 Part 1: Updating Database 1/6/2015 1 Learning Objectives 1. To consider how to do insertions and deletions in SQL 2. To consider amendments (updates) to a relation 3. To consider

More information

SQL Structured Query Language Introduction

SQL Structured Query Language Introduction SQL Structured Query Language Introduction Rifat Shahriyar Dept of CSE, BUET Tables In relational database systems data are represented using tables (relations). A query issued against the database also

More information

D B M G. SQL language: basics. Managing tables. Creating a table Modifying table structure Deleting a table The data dictionary Data integrity

D B M G. SQL language: basics. Managing tables. Creating a table Modifying table structure Deleting a table The data dictionary Data integrity SQL language: basics Creating a table Modifying table structure Deleting a table The data dictionary Data integrity 2013 Politecnico di Torino 1 Creating a table Creating a table (1/3) The following SQL

More information

Further GroupBy & Extend Operations

Further GroupBy & Extend Operations Slide 1 Further GroupBy & Extend Operations Objectives of the Lecture : To consider whole relation Grouping; To consider the SQL Grouping option Having; To consider the Extend operator & its implementation

More information

SQL Simple Queries. Chapter 3.1 V3.01. Napier University

SQL Simple Queries. Chapter 3.1 V3.01. Napier University SQL Simple Queries Chapter 3.1 V3.01 Copyright @ Napier University Introduction SQL is the Structured Query Language It is used to interact with the DBMS (database management system) SQL can Create Schemas

More information

NULLs & Outer Joins. Objectives of the Lecture :

NULLs & Outer Joins. Objectives of the Lecture : Slide 1 NULLs & Outer Joins Objectives of the Lecture : To consider the use of NULLs in SQL. To consider Outer Join Operations, and their implementation in SQL. Slide 2 Missing Values : Possible Strategies

More information

COSC 304 Introduction to Database Systems SQL DDL. Dr. Ramon Lawrence University of British Columbia Okanagan

COSC 304 Introduction to Database Systems SQL DDL. Dr. Ramon Lawrence University of British Columbia Okanagan COSC 304 Introduction to Database Systems SQL DDL Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca SQL Overview Structured Query Language or SQL is the standard query language

More information

Data Modelling and Databases. Exercise Session 7: Integrity Constraints

Data Modelling and Databases. Exercise Session 7: Integrity Constraints Data Modelling and Databases Exercise Session 7: Integrity Constraints 1 Database Design Textual Description Complete Design ER Diagram Relational Schema Conceptual Modeling Logical Modeling Physical Modeling

More information

SQL. Char (30) can store ram, ramji007 or 80- b

SQL. Char (30) can store ram, ramji007 or 80- b SQL In Relational database Model all the information is stored on Tables, these tables are divided into rows and columns. A collection on related tables are called DATABASE. A named table in a database

More information

Relational Data Structure and Concepts. Structured Query Language (Part 1) The Entity Integrity Rules. Relational Data Structure and Concepts

Relational Data Structure and Concepts. Structured Query Language (Part 1) The Entity Integrity Rules. Relational Data Structure and Concepts Relational Data Structure and Concepts Structured Query Language (Part 1) Two-dimensional tables whose attributes values are atomic. At every row-and-column position within the table, there always exists

More information

SQL DATA DEFINITION: KEY CONSTRAINTS. CS121: Relational Databases Fall 2017 Lecture 7

SQL DATA DEFINITION: KEY CONSTRAINTS. CS121: Relational Databases Fall 2017 Lecture 7 SQL DATA DEFINITION: KEY CONSTRAINTS CS121: Relational Databases Fall 2017 Lecture 7 Data Definition 2 Covered most of SQL data manipulation operations Continue exploration of SQL data definition features

More information

Downloaded from

Downloaded from Lesson 16: Table and Integrity Constraints Integrity Constraints are the rules that a database must follow at all times. Various Integrity constraints are as follows:- 1. Not Null: It ensures that we cannot

More information

The Relational Model. Chapter 3

The Relational Model. Chapter 3 The Relational Model Chapter 3 Why Study the Relational Model? Most widely used model. Systems: IBM DB2, Informix, Microsoft (Access and SQL Server), Oracle, Sybase, MySQL, etc. Legacy systems in older

More information

The Relational Model. Chapter 3. Comp 521 Files and Databases Fall

The Relational Model. Chapter 3. Comp 521 Files and Databases Fall The Relational Model Chapter 3 Comp 521 Files and Databases Fall 2012 1 Why Study the Relational Model? Most widely used model by industry. IBM, Informix, Microsoft, Oracle, Sybase, etc. It is simple,

More information

Objectives. After completing this lesson, you should be able to do the following:

Objectives. After completing this lesson, you should be able to do the following: Objectives After completing this lesson, you should be able to do the following: Describe the types of problems that subqueries can solve Define subqueries List the types of subqueries Write single-row

More information

The Relational Model. Chapter 3. Database Management Systems, R. Ramakrishnan and J. Gehrke 1

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

More information

Creating SQL Tables and using Data Types

Creating SQL Tables and using Data Types Creating SQL Tables and using Data Types Aims: To learn how to create tables in Oracle SQL, and how to use Oracle SQL data types in the creation of these tables. Outline of Session: Given a simple database

More information

Trigger is a stored procedure which is called implicitly by oracle engine whenever a insert, update or delete statement is fired.

Trigger is a stored procedure which is called implicitly by oracle engine whenever a insert, update or delete statement is fired. Aim:- TRIGGERS Trigger is a stored procedure which is called implicitly by oracle engine whenever a insert, update or delete statement is fired. Advantages of database triggers: ---> Data is generated

More information

Database Management Systems,

Database Management Systems, Database Management Systems SQL Query Language (1) 1 Topics Introduction SQL History Domain Definition Elementary Domains User-defined Domains Creating Tables Constraint Definition INSERT Query SELECT

More information

The Relational Model. Chapter 3. Comp 521 Files and Databases Fall

The Relational Model. Chapter 3. Comp 521 Files and Databases Fall The Relational Model Chapter 3 Comp 521 Files and Databases Fall 2014 1 Why the Relational Model? Most widely used model by industry. IBM, Informix, Microsoft, Oracle, Sybase, MySQL, Postgres, Sqlite,

More information

5 Integrity Constraints and Triggers

5 Integrity Constraints and Triggers 5 Integrity Constraints and Triggers 5.1 Integrity Constraints In Section 1 we have discussed three types of integrity constraints: not null constraints, primary keys, and unique constraints. In this section

More information

Introduction to Data Management. Lecture #4 (E-R Relational Translation)

Introduction to Data Management. Lecture #4 (E-R Relational Translation) Introduction to Data Management Lecture #4 (E-R Relational Translation) Instructor: Mike Carey mjcarey@ics.uci.edu Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 Announcements v Today

More information

The Relational Model 2. Week 3

The Relational Model 2. Week 3 The Relational Model 2 Week 3 1 We have seen how to create a database schema, how do we create an actual database on our computers? professor(pid : string, name : string) course(pid : string, number :

More information

Database Applications (15-415)

Database Applications (15-415) Database Applications (15-415) The Relational Model Lecture 3, January 18, 2015 Mohammad Hammoud Today Last Session: The entity relationship (ER) model Today s Session: ER model (Cont d): conceptual design

More information

Programming the Database

Programming the Database Programming the Database Today s Lecture 1. Stored Procedures 2. Functions BBM471 Database Management Systems Dr. Fuat Akal akal@hacettepe.edu.tr 3. Cursors 4. Triggers 5. Dynamic SQL 2 Stored Procedures

More information

Why Study the Relational Model? The Relational Model. Relational Database: Definitions. The SQL Query Language. Relational Query Languages

Why Study the Relational Model? The Relational Model. Relational Database: Definitions. The SQL Query Language. Relational Query Languages Why Study the Relational Model? The Relational Model Most widely used model. Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc. Legacy systems in older models E.G., IBM s IMS Recent competitor: object-oriented

More information

High-Level Database Models (ii)

High-Level Database Models (ii) ICS 321 Spring 2011 High-Level Database Models (ii) Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 1 Logical DB Design: ER to Relational Entity sets to

More information

Translating an ER Diagram to a Relational Schema

Translating an ER Diagram to a Relational Schema Translating an ER Diagram to a Relational Schema CS386/586 Introduction to Database Systems, Lois Delcambre 1999-2009 Slide 1 Translate each entity set into a table, with keys. Entity set: represented

More information

Let s briefly review important EER inheritance concepts

Let s briefly review important EER inheritance concepts Let s briefly review important EER inheritance concepts 1 is-a relationship Copyright (c) 2011 Pearson Education 2 Basic Constraints Partial / Disjoint: Single line / d in circle Each entity can be an

More information

The Relational Model Constraints and SQL DDL

The Relational Model Constraints and SQL DDL The Relational Model Constraints and SQL DDL Week 2-3 Weeks 2-3 MIE253-Consens 1 Schedule Week Date Lecture Topic 1 Jan 9 Introduction to Data Management 2 Jan 16 The Relational Model 3 Jan. 23 Constraints

More information

Relational Model. Topics. Relational Model. Why Study the Relational Model? Linda Wu (CMPT )

Relational Model. Topics. Relational Model. Why Study the Relational Model? Linda Wu (CMPT ) Topics Relational Model Linda Wu Relational model SQL language Integrity constraints ER to relational Views (CMPT 354 2004-2) Chapter 3 CMPT 354 2004-2 2 Why Study the Relational Model? Most widely used

More information

SQL: Concepts. Todd Bacastow IST 210: Organization of Data 2/17/ IST 210

SQL: Concepts. Todd Bacastow IST 210: Organization of Data 2/17/ IST 210 SQL: Concepts Todd Bacastow IST 210: Organization of Data 2/17/2004 1 Design questions How many entities are there? What are the major entities? What are the attributes of each entity? Is there a unique

More information

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

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

More information

SQL DATA DEFINITION LANGUAGE

SQL DATA DEFINITION LANGUAGE 9/27/16 DATABASE SCHEMAS IN SQL SQL DATA DEFINITION LANGUAGE SQL is primarily a query language, for getting information from a database. SFWR ENG 3DB3 FALL 2016 But SQL also includes a data-definition

More information

Introduction to Data Management. Lecture #5 (E-R Relational, Cont.)

Introduction to Data Management. Lecture #5 (E-R Relational, Cont.) Introduction to Data Management Lecture #5 (E-R Relational, Cont.) Instructor: Mike Carey mjcarey@ics.uci.edu Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 Announcements v HW#1 is due

More information

Introduction to Data Management. Lecture #4 (E-R à Relational Design)

Introduction to Data Management. Lecture #4 (E-R à Relational Design) Introduction to Data Management Lecture #4 (E-R à Relational Design) Instructor: Mike Carey mjcarey@ics.uci.edu Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 Announcements v Reminders:

More information

In This Lecture. The Relational Model. The Relational Model. Relational Data Structure. Unnamed and named tuples. New thing:scheme (and attributes)

In This Lecture. The Relational Model. The Relational Model. Relational Data Structure. Unnamed and named tuples. New thing:scheme (and attributes) Database Systems Lecture 3 Natasha Alechina In This Lecture Relational data integrity For more information Connolly and Begg chapter 3 E.F. Codd s paper `A Relational Model of Data for Large Shared Data

More information

Data Modeling. Yanlei Diao UMass Amherst. Slides Courtesy of R. Ramakrishnan and J. Gehrke

Data Modeling. Yanlei Diao UMass Amherst. Slides Courtesy of R. Ramakrishnan and J. Gehrke Data Modeling Yanlei Diao UMass Amherst Slides Courtesy of R. Ramakrishnan and J. Gehrke 1 Outline v Conceptual Design: ER Model v Relational Model v Logical Design: from ER to Relational 2 Conceptual

More information

Relational Model History. COSC 416 NoSQL Databases. Relational Model (Review) Relation Example. Relational Model Definitions. Relational Integrity

Relational Model History. COSC 416 NoSQL Databases. Relational Model (Review) Relation Example. Relational Model Definitions. Relational Integrity COSC 416 NoSQL Databases Relational Model (Review) Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca Relational Model History The relational model was proposed by E. F. Codd

More information

Database Systems ( 資料庫系統 )

Database Systems ( 資料庫系統 ) Database Systems ( 資料庫系統 ) 9.28.2011 Lecture #3 1 Course Administration Please download HW #1 from course homepage It is due 10/12/2011. This lecture: R&G Chapter 3 Next week reading: R&G Chapter 41~ 4.1

More information

COSC344 Database Theory and Applications. Lecture 5 SQL - Data Definition Language. COSC344 Lecture 5 1

COSC344 Database Theory and Applications. Lecture 5 SQL - Data Definition Language. COSC344 Lecture 5 1 COSC344 Database Theory and Applications Lecture 5 SQL - Data Definition Language COSC344 Lecture 5 1 Overview Last Lecture Relational algebra This Lecture Relational algebra (continued) SQL - DDL CREATE

More information

Databases - 4. Other relational operations and DDL. How to write RA expressions for dummies

Databases - 4. Other relational operations and DDL. How to write RA expressions for dummies Databases - 4 Other relational operations and DDL How to write RA expressions for dummies Step 1: Identify the relations required and CP them together Step 2: Add required selections to make the CP Step

More information

The Entity-Relationship Model. Overview of Database Design

The Entity-Relationship Model. Overview of Database Design The Entity-Relationship Model Chapter 2, Chapter 3 (3.5 only) Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 Overview of Database Design Conceptual design: (ER Model is used at this stage.)

More information

Chapter 8 INTEGRITY 1

Chapter 8 INTEGRITY 1 Chapter 8 INTEGRITY 1 Introduction Integrity refers to the correctness or accuracy of data in the database For examples: In Supplier-Part-Project database, the status values might have to be in the range

More information

Data about data is database Select correct option: True False Partially True None of the Above

Data about data is database Select correct option: True False Partially True None of the Above Within a table, each primary key value. is a minimal super key is always the first field in each table must be numeric must be unique Foreign Key is A field in a table that matches a key field in another

More information

Full file at

Full file at SQL for SQL Server 1 True/False Questions Chapter 2 Creating Tables and Indexes 1. In order to create a table, three pieces of information must be determined: (1) the table name, (2) the column names,

More information

SQL - Subqueries and. Schema. Chapter 3.4 V4.0. Napier University

SQL - Subqueries and. Schema. Chapter 3.4 V4.0. Napier University SQL - Subqueries and Chapter 3.4 V4.0 Copyright @ Napier University Schema Subqueries Subquery one SELECT statement inside another Used in the WHERE clause Subqueries can return many rows. Subqueries can

More information

The Relational Model

The Relational Model The Relational Model What is the Relational Model Relations Domain Constraints SQL Integrity Constraints Translating an ER diagram to the Relational Model and SQL Views A relational database consists

More information

Databases - 5. Problems with the relational model Functions and sub-queries

Databases - 5. Problems with the relational model Functions and sub-queries Databases - 5 Problems with the relational model Functions and sub-queries Problems (1) To store information about real life entities, we often have to cut them up into separate tables Problems (1) To

More information

Creating Tables, Defining Constraints. Rose-Hulman Institute of Technology Curt Clifton

Creating Tables, Defining Constraints. Rose-Hulman Institute of Technology Curt Clifton Creating Tables, Defining Constraints Rose-Hulman Institute of Technology Curt Clifton Outline Data Types Creating and Altering Tables Constraints Primary and Foreign Key Constraints Row and Tuple Checks

More information

Table : Purchase. Field DataType Size Constraints CustID CHAR 5 Primary key CustName Varchar 30 ItemName Varchar 30 PurchaseDate Date

Table : Purchase. Field DataType Size Constraints CustID CHAR 5 Primary key CustName Varchar 30 ItemName Varchar 30 PurchaseDate Date Q1. Write SQL query for the following : (i) To create above table as per specification given (ii) To insert 02 records as per your choice (iii) Display the Item name, qty & s of all items purchased by

More information

CIS 330: Applied Database Systems. ER to Relational Relational Algebra

CIS 330: Applied Database Systems. ER to Relational Relational Algebra CIS 330: Applied Database Systems ER to Relational Relational Algebra 1 Logical DB Design: ER to Relational Entity sets to tables: ssn name Employees lot CREATE TABLE Employees (ssn CHAR(11), name CHAR(20),

More information

Database Design Process

Database Design Process Database Design Process Real World Functional Requirements Requirements Analysis Database Requirements Functional Analysis Access Specifications Application Pgm Design E-R Modeling Choice of a DBMS Data

More information

COSC 304 Introduction to Database Systems. Entity-Relationship Modeling

COSC 304 Introduction to Database Systems. Entity-Relationship Modeling COSC 304 Introduction to Database Systems Entity-Relationship Modeling Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca Conceptual Database Design Conceptual database design

More information

CS121 MIDTERM REVIEW. CS121: Relational Databases Fall 2017 Lecture 13

CS121 MIDTERM REVIEW. CS121: Relational Databases Fall 2017 Lecture 13 CS121 MIDTERM REVIEW CS121: Relational Databases Fall 2017 Lecture 13 2 Before We Start Midterm Overview 3 6 hours, multiple sittings Open book, open notes, open lecture slides No collaboration Possible

More information

Information Systems. Database System Architecture. Relational Databases. Nikolaj Popov

Information Systems. Database System Architecture. Relational Databases. Nikolaj Popov Information Systems Database System Architecture. Relational Databases Nikolaj Popov Research Institute for Symbolic Computation Johannes Kepler University of Linz, Austria popov@risc.uni-linz.ac.at Outline

More information

SQL DATA DEFINITION LANGUAGE

SQL DATA DEFINITION LANGUAGE SQL DATA DEFINITION LANGUAGE DATABASE SCHEMAS IN SQL SQL is primarily a query language, for getting information from a database. DML: Data Manipulation Language SFWR ENG 3DB3 FALL 2016 MICHAEL LIUT (LIUTM@MCMASTER.CA)

More information

Creating and Managing Tables Schedule: Timing Topic

Creating and Managing Tables Schedule: Timing Topic 9 Creating and Managing Tables Schedule: Timing Topic 30 minutes Lecture 20 minutes Practice 50 minutes Total Objectives After completing this lesson, you should be able to do the following: Describe the

More information

RDBMS Using Oracle. BIT-4 Lecture Week 3. Lecture Overview

RDBMS Using Oracle. BIT-4 Lecture Week 3. Lecture Overview RDBMS Using Oracle BIT-4 Lecture Week 3 Lecture Overview Creating Tables, Valid and Invalid table names Copying data between tables Character and Varchar2 DataType Size Define Variables in SQL NVL and

More information

DATABASE DEVELOPMENT (H4)

DATABASE DEVELOPMENT (H4) IMIS HIGHER DIPLOMA QUALIFICATIONS DATABASE DEVELOPMENT (H4) Friday 3 rd June 2016 10:00hrs 13:00hrs DURATION: 3 HOURS Candidates should answer ALL the questions in Part A and THREE of the five questions

More information

Database System Concepts

Database System Concepts Chapter 4(+8): Advanced SQL Departamento de Engenharia Informática Instituto Superior Técnico 1 st Semester 2007/2008 Slides (fortemente) baseados nos slides oficiais do livro c Silberschatz, Korth and

More information

HOW TO CREATE AND MAINTAIN DATABASES AND TABLES. By S. Sabraz Nawaz Senior Lecturer in MIT FMC, SEUSL

HOW TO CREATE AND MAINTAIN DATABASES AND TABLES. By S. Sabraz Nawaz Senior Lecturer in MIT FMC, SEUSL HOW TO CREATE AND MAINTAIN DATABASES AND TABLES By S. Sabraz Nawaz Senior Lecturer in MIT FMC, SEUSL What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate

More information

King Fahd University of Petroleum and Minerals

King Fahd University of Petroleum and Minerals 1 King Fahd University of Petroleum and Minerals Information and Computer Science Department ICS 334: Database Systems Semester 041 Major Exam 1 18% ID: Name: Section: Grades Section Max Scored A 5 B 25

More information

High Level Database Models

High Level Database Models ICS 321 Fall 2011 High Level Database Models Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 9/21/2011 Lipyeow Lim -- University of Hawaii at Manoa 1 Database

More information

The Relational Model (ii)

The Relational Model (ii) ICS 321 Fall 2009 The Relational Model (ii) Asst. Prof. Lipyeow Lim Information and Computer Science Department University of Hawaii at Manoa 1 Internet Book Store Example Isbn title author qty price year

More information

Database Foundations. 6-3 Data Definition Language (DDL) Copyright 2015, Oracle and/or its affiliates. All rights reserved.

Database Foundations. 6-3 Data Definition Language (DDL) Copyright 2015, Oracle and/or its affiliates. All rights reserved. Database Foundations 6-3 Roadmap You are here Introduction to Oracle Application Express Structured Query Language (SQL) Data Definition Language (DDL) Data Manipulation Language (DML) Transaction Control

More information

Database Management System Dr. S. Srinath Department of Computer Science & Engineering Indian Institute of Technology, Madras Lecture No.

Database Management System Dr. S. Srinath Department of Computer Science & Engineering Indian Institute of Technology, Madras Lecture No. Database Management System Dr. S. Srinath Department of Computer Science & Engineering Indian Institute of Technology, Madras Lecture No. # 13 Constraints & Triggers Hello and welcome to another session

More information

SQL. SQL DDL Statements

SQL. SQL DDL Statements SQL Structured Query Language Declarative Specify the properties that should hold in the result, not how to obtain the result Complex queries have procedural elements International Standard SQL1 (1986)

More information

Oracle EXAM - 1Z Oracle Database SQL Expert. Buy Full Product.

Oracle EXAM - 1Z Oracle Database SQL Expert. Buy Full Product. Oracle EXAM - 1Z0-047 Oracle Database SQL Expert Buy Full Product http://www.examskey.com/1z0-047.html Examskey Oracle 1Z0-047 exam demo product is here for you to test the quality of the product. This

More information

Maintaining Data 3.3.1

Maintaining Data 3.3.1 Maintaining Data Course materials may not be reproduced in whole or in part without the prior written permission of IBM. 4.0.3 3.3.1 Unit Objectives After completing this unit, you should be able to: Create

More information

Designing Tables for an Oracle Database System. From theory to practice

Designing Tables for an Oracle Database System. From theory to practice Designing Tables for an Oracle Database System Database Course, Fall 2004 From theory to practice The Entity- Relationship model: a convenient way of representing the world. The Relational model: a model

More information

The Relational Model. Relational Data Model Relational Query Language (DDL + DML) Integrity Constraints (IC)

The Relational Model. Relational Data Model Relational Query Language (DDL + DML) Integrity Constraints (IC) The Relational Model Relational Data Model Relational Query Language (DDL + DML) Integrity Constraints (IC) Why Study the Relational Model? Most widely used model in Commercial DBMSs: Vendors: IBM, Microsoft,

More information

Lab # 4. Data Definition Language (DDL)

Lab # 4. Data Definition Language (DDL) Islamic University of Gaza Faculty of Engineering Department of Computer Engineering ECOM 4113: Lab # 4 Data Definition Language (DDL) Eng. Haneen El-Masry November, 2014 2 Objective To be familiar with

More information

Domain Constraints Referential Integrity Assertions Triggers. Authorization Authorization in SQL

Domain Constraints Referential Integrity Assertions Triggers. Authorization Authorization in SQL Chapter 6: Integrity and Security Domain Constraints Referential Integrity Assertions Triggers Security Authorization Authorization in SQL 6.1 Domain Constraints Integrity constraints guard against accidental

More information

Database Management Systems Triggers

Database Management Systems Triggers Database Management Systems Triggers 1 Triggers Active Database Systems Oracle Triggers DB2 Triggers Differences between Oracle and DB2 Trigger Design 2 Database Management Systems Active Database Systems

More information

Exam Actual. Higher Quality. Better Service! QUESTION & ANSWER

Exam Actual. Higher Quality. Better Service! QUESTION & ANSWER Higher Quality Better Service! Exam Actual QUESTION & ANSWER Accurate study guides, High passing rate! Exam Actual provides update free of charge in one year! http://www.examactual.com Exam : 1Z0-047 Title

More information

1 SQL Structured Query Language

1 SQL Structured Query Language 1 SQL Structured Query Language 1.1 Tables In relational database systems (DBS) data are represented using tables (relations). A query issued against the DBS also results in a table. A table has the following

More information

Visit for more.

Visit  for more. Chapter 9: More On Database & SQL Advanced Concepts Informatics Practices Class XII (CBSE Board) Revised as per CBSE Curriculum 2015 Visit www.ip4you.blogspot.com for more. Authored By:- Rajesh Kumar Mishra,

More information

The DBMS accepts requests for data from the application program and instructs the operating system to transfer the appropriate data.

The DBMS accepts requests for data from the application program and instructs the operating system to transfer the appropriate data. Managing Data Data storage tool must provide the following features: Data definition (data structuring) Data entry (to add new data) Data editing (to change existing data) Querying (a means of extracting

More information

The Relational Model. Outline. Why Study the Relational Model? Faloutsos SCS object-relational model

The Relational Model. Outline. Why Study the Relational Model? Faloutsos SCS object-relational model The Relational Model CMU SCS 15-415 C. Faloutsos Lecture #3 R & G, Chap. 3 Outline Introduction Integrity constraints (IC) Enforcing IC Querying Relational Data ER to tables Intro to Views Destroying/altering

More information

Why Relational Databases? Relational databases allow for the storage and analysis of large amounts of data.

Why Relational Databases? Relational databases allow for the storage and analysis of large amounts of data. DATA 301 Introduction to Data Analytics Relational Databases Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca DATA 301: Data Analytics (2) Why Relational Databases? Relational

More information

PASS4TEST. IT Certification Guaranteed, The Easy Way! We offer free update service for one year

PASS4TEST. IT Certification Guaranteed, The Easy Way!  We offer free update service for one year PASS4TEST \ We offer free update service for one year Exam : 1z0-071 Title : Oracle Database 12c SQL Vendor : Oracle Version : DEMO Get Latest & Valid 1z0-071 Exam's Question and Answers 1 from Pass4test.

More information

The Relational Model. Roadmap. Relational Database: Definitions. Why Study the Relational Model? Relational database: a set of relations

The Relational Model. Roadmap. Relational Database: Definitions. Why Study the Relational Model? Relational database: a set of relations The Relational Model CMU SCS 15-415/615 C. Faloutsos A. Pavlo Lecture #3 R & G, Chap. 3 Roadmap Introduction Integrity constraints (IC) Enforcing IC Querying Relational Data ER to tables Intro to Views

More information

SQL STRUCTURED QUERY LANGUAGE

SQL STRUCTURED QUERY LANGUAGE STRUCTURED QUERY LANGUAGE SQL Structured Query Language 4.1 Introduction Originally, SQL was called SEQUEL (for Structured English QUery Language) and implemented at IBM Research as the interface for an

More information

The Relational Model

The Relational Model The Relational Model UVic C SC 370, Fall 2002 Daniel M. German Department of Computer Science University of Victoria 3 1 The Relational Model CSC 370 dmgerman@uvic.ca Overview How is data represented in

More information

Relational data model

Relational data model Relational data model Iztok Savnik FAMNIT, 18/19 Why Study the Relational Model? Most widely used model. Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc. Legacy systems in older models E.G., IBM

More information

Database Management Systems. Chapter 3 Part 2

Database Management Systems. Chapter 3 Part 2 Database Management Systems Chapter 3 Part 2 The Relational Model Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 Logical DB Design: ER to Relational Entity sets to tables: CREATE TABLE

More information

Database Management Systems. Chapter 3 Part 1

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

More information

Lecture7: SQL Overview, Oracle Data Type, DDL and Constraints Part #2

Lecture7: SQL Overview, Oracle Data Type, DDL and Constraints Part #2 IS220 : Database Fundamentals College of Computer and Information Sciences - Information Systems Dept. Lecture7: SQL Overview, Oracle Data Type, DDL and Constraints Part #2 Ref. Chapter6 Prepared by L.

More information

CSC 453 Database Technologies. Tanu Malik DePaul University

CSC 453 Database Technologies. Tanu Malik DePaul University CSC 453 Database Technologies Tanu Malik DePaul University A Data Model A notation for describing data or information. Consists of mostly 3 parts: Structure of the data Data structures and relationships

More information

Lecture 3 (Part 2) Akhtar Ali

Lecture 3 (Part 2) Akhtar Ali Normalisation Lecture 3 (Part 2) Akhtar Ali 10/14/2014 1 Learning Objectives 1. To consider the process of Normalisation 2. To consider the definition and application of 1NF 3. To consider the definition

More information

Comp 5311 Database Management Systems. 4b. Structured Query Language 3

Comp 5311 Database Management Systems. 4b. Structured Query Language 3 Comp 5311 Database Management Systems 4b. Structured Query Language 3 1 SQL as Data Definition Language Creates the Students relation. The type (domain) of each field is specified, and enforced by the

More information

CS2300: File Structures and Introduction to Database Systems

CS2300: File Structures and Introduction to Database Systems CS2300: File Structures and Introduction to Database Systems Lecture 14: SQL Doug McGeehan From Theory to Practice The Entity-Relationship Model: a convenient way of representing the world. The Relational

More information

Illustrative Example of Logical Database Creation

Illustrative Example of Logical Database Creation Illustrative Example of Logical Database Creation A small RAQUEL DB is created to illustrate what is involved as regards the logical schemas of a RAQUEL DB. Create a Database or ExampleDB

More information

UFCEKG 20 2 : Data, Schemas and Applications

UFCEKG 20 2 : Data, Schemas and Applications Lecture 11 UFCEKG 20 2 : Data, Schemas and Applications Lecture 11 Database Theory & Practice (5) : Introduction to the Structured Query Language (SQL) Origins & history Early 1970 s IBM develops Sequel

More information

1 Prepared By Heena Patel (Asst. Prof)

1 Prepared By Heena Patel (Asst. Prof) Topic 1 1. What is difference between Physical and logical data 3 independence? 2. Define the term RDBMS. List out codd s law. Explain any three in detail. ( times) 3. What is RDBMS? Explain any tow Codd

More information

1.3. Joins Introduction Access across relations Miniworld approximation Pointing mechanism

1.3. Joins Introduction Access across relations Miniworld approximation Pointing mechanism 1.3. Joins In this lecture we look at... 1.3.01. Introduction Recap: pulling data out of individual relations By row, by column Select and project Access across multiple relations Miniworld approximation

More information

The Relational Model of Data (ii)

The Relational Model of Data (ii) ICS 321 Fall 2013 The Relational Model of Data (ii) Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 1 Defining Relational Schema in SQL Two aspects: Data

More information