Amendments & Transactions

Size: px
Start display at page:

Download "Amendments & Transactions"

Transcription

1 Slide 1 Amendments & Transactions Objectives of the Lecture : To consider amendments to a relation; To consider transactions in SQL.

2 Slide 2 Relational Amendment Strictly speaking, relational amendment is unnecessary. We could just use a Delete followed by an Insert. RelVar Delete set of tuples to be amended RelVar Insert set of tuples that have been amended However it is more convenient for the user to have a single assignment that does the complete amendment. To achieve this, it must be possible to : amend a subset of a relation s tuples; amend a subset of a tuple s attributes. Subset of RelVar Amend[ amendment to subset of attributes ] Note the following : A subset could be all the tuples in a relation / attributes in a tuple, or a proper subset - perhaps just one - tuple in a relation / attribute in a tuple (or even in theory the empty subset, although this would result in no amendments being made!). The amendment is not like a traditional assignment, because we are not assigning tuples to the relvar, but assigning changes to a subset of the relvar.

3 Slide 3 Example of Amendment EMPLOYEE ENo EName M-S Sal E3 1 Smith 5 2S 12,500 2 E5 2 Mitchell 6 M 4 21, E1 3 Robson 7 D 6 32,500 6 E6 4 E8 Blake 8 Jones 8M W 54, ,000 EMPLOYEE ENo EName M-S Sal E3 1 Smith 5 2S 12,500 14,250 2 E5 2 Mitchell 6 M 4 21,000 23, E1 3 Robson 7 D 6 32,500 36,250 6 E6 4 Blake 8 8M 54,000 59,900 8 E8 Jones W 68,000 75,300 Amend[Sal (1.1 * Sal )] Variable Amendment Resulting value of variable. All salaries increased by 10% plus 500. The relational variable EMPLOYEE is graphically displayed. The amendment is not a relational value but an instruction to amend an attribute. The instruction is expressed like a traditional programming language assignment. The LHS of this attribute assignment is the name of the attribute whose value is to be amended; the RHS of it is an expression that evaluates to the new value of the attribute that is to replace the original value. In the above example, the new attribute value of Sal is based in part on the old attribute value of Sal. The assignment of a new attribute value is then applied to all the tuples on the LHS of the relational assignment.

4 Slide 4 Amendment in Principle Subset of RelVar Amend[ set of attribute assignments ] This is a subset of any relation in the DB. The set of attribute assignments are executed in parallel. Each of one or more assignments replaces an attribute value with a new value. In principle, there can be any number of tuples in the set, including zero! The new attribute value may be : - a scalar constant; - an attribute value, of the same type, and taken from the same tuple; - a function or calculation producing a scalar value; - any combination of the above. As many or as few attributes as required can be amended in the amendment statement. The order in which the amendments are carried out in each tuple does not matter; logically they are all carried out simultaneously in parallel, and independently of each other. Likewise each tuple on the LHS of the relational assignment is logically amended simultaneously in parallel, and independently of each other. The implementation may well have to loop through each tuple in turn, and through each attribute in each tuple in turn to actually do the work, but this will be invisible to the DB user. The RHS of an attribute assignment can be any valid expression, from a simple constant value (e.g. 3, Julie ) to a very complicated calculation. If one or more attribute names appears in the RHS of an attribute assignment, then the values of those named attributes that will be used will be those in the same tuple as that of the attribute value that is being amended.

5 Slide 5 SQL : Amend The SQL syntax is :- Update RELATION_NAME Set attribute assignment(s) Where condition ; In the Where phrase, a condition is written that selects the subset of required tuples from RELATION_NAME. These tuples are then amended. The Where phrase is optional. One can just write Update RELATION_NAME Set attribute assignment(s) ; In this case, all the tuples in RELATION_NAME are amended. In SQL, update is given the more specific meaning of amend. The keyword Update at the beginning of the statement indicates that an amendment is to be carried out. Thus the first 2 words of an amendment statement correspond to the amendment assignment and the LHS relvar, the Set phrase contains the attribute amendment assignments (using = as the assignment symbol) with the following Where phrase specifying which tuples of the relvar are to be amended (and the omission of the Where phrase specifying that all the tuples in the relvar are to be amended). Note that Set here means set the column(s) to ; it is not referring to a mathematical set. The Where phrase is used in an SQL Update in exactly the same way as it is used in an SQL Delete.

6 Slide 6 Examples of SQL Amend 1. Amend all the tuples to give everyone a salary increase of 10% plus 500; i.e. the earlier graphical example : Update EMPLOYEE Set Sal = ( 1.1 * Sal ) ; 2. Amend Mitchell s name to Wilson, give him/her a new salary of 27,000, and amend their marital status to widowed : Update EMPLOYEE Set Sal = 27000, EName = Wilson, M-S = W ; This changes the three attributes values in every tuple affected by the amendment. Oops!! Every tuple in EMPLOYEE is affected by this amendment. Can the effect of this amendment be undone? Note how the Where phrase (or lack of it) determines which tuples are amended. In the first example above, because the new salary depends on the old salary, although the same calculation will be applied in each tuple, each salary value can be updated to a different value. In the second example above, because the new values of Sal, EName and M-S are constants, every tuple in EMPLOYEE will be updated to a salary of 27,000, a name of Wilson, and a marital status of widowed!

7 Slide 7 Further Example of SQL Amend Update EMPLOYEE Set Sal = 27000, EName = Wilson, M-S = W Where ENo = E5 ; EMPLOYEE ENo EName M-S Sal E5 2 Mitchell Wilson 6 4M 4W 21,000 27,000 4 E6 4 Blake 8 8M 54,000 8 E1 3 Robson 7 6D 32,500 6 E3 1 Smith 5 2S 12,500 2 E8 Jones W 68,000 Only employee E5 s attribute values are altered. A candidate key value was used to pick out the correct individual tuple. Comparing this with the earlier graphical display of the EMPLOYEE relation, only one tuple in it has now been amended. To be certain of amending one specific tuple, a candidate key must be used in the condition, because it is the only thing guaranteed to identify one particular tuple. It is also possible to amend an attribute so that it becomes null instead of containing a value. For example : Update EMPLOYEE Set Sal = NULL Where ENo = E5 ; This sets the value of E5 s salary to be null. Update EMPLOYEE Set Sal = NULL ; This sets everyone s salary to be null! Note that = is still used for value assignment, even though no value is actually being assigned! (Indeed null could replace a value!) Note that, once again, NULL is a keyword here; so it can be in upper or lower case as long as it is not in speech marks (which will cause it to be treated as just another piece of text).

8 Slide 8 Integrity Constraints A tuple to be inserted into a relation must meet all the integrity constraints for that relation. If it does not, it is rejected with an error message. An amended version of a tuple must meet all the integrity constraints for that relation. If it does not, it is rejected with an error message. Even the deletion of a tuple can be rejected (!) if the deletion breaks an integrity constraint, e.g. to keep a fixed number of tuples in the relation. So far, we have assumed none of the insertions, deletions, or amendments break the integrity constraints. In practice this will not always be so. We therefore need to consider this aspect of updating.

9 Slide 9 Time of Validation Checking It is possible to check some integrity constraints immediately after the update. They are : data type constraints, candidate key constraints, some referential integrity constraints, some ad hoc constraints. There is no necessity to delay the checking. It is not possible to check other integrity constraints immediately after the update. They must be deferred to an appropriate time. They are : some referential integrity constraints, some ad hoc constraints. Update is used here with its general meaning of any alteration of the relation be it due to an insertion, a deletion, or an amendment. From the DB user s point of view, the DBMS will appear to carry out an update, then check all the integrity constraints, and finally undo the update if any constraint is broken. An efficient implementation will validate the update before executing it.

10 Slide 10 Example of Deferred Checking CAR RegNo K123 5ABC W811 6 STA JON 71 V771 8PQ Type Corsa 1.3 Starlet GLi Jaguar XK Volvo S80 W333 LNY Focus 1.6L Owner E3 E5 2 E1 E6 E4 EMPLOYEE ENo EName M-S Sal E3 1 E5 2 E1 3 Smith 5 Mitchell 6 Robson 7 2S M 4 D 6 12, , ,500 6 E6 4 E8 E4 Blake 8 8M 54,000 8 Jones W 68,000 Archer S 40,000 Referential Integrity means that the new CAR tuple can only be added after the new EMPLOYEE tuple. Suppose a new employee with ENo E5 joins the company and has a car. A tuple in each of the relations EMPLOYEE and CAR will need to be inserted to represent this. If the new CAR tuple were added before the new EMPLOYEE tuple, then the foreign key Owner in CAR would not reference any candidate key value in EMPLOYEE, thereby breaking the referential integrity constraint. If the two tuples were added in the reverse order, there would be no problem; however there is no certainty as to which order will be used, because from the user s point of view, they are both part of one transaction.

11 Slide 11 Transactions A transaction is a means of managing updates. At the end of a transaction, the DB must be in a valid state, i.e. all integrity constraints must apply to all relations in the DB. Definition : a transaction is a complete and indivisible logical unit of work to update the database. It is completely atomic even when it consists of several updates. All integrity checks, whatever their nature, must be carried out by the end of the transaction, to ensure that the DB remains in a valid state. The addition of a new employee and their car is an example of a transaction, as is the addition of a new employee who has no car. Likewise the deletion of an employee, with or without their car, is a transaction. Transactions can involve one relation or many. They can also be require insertions, deletions and/or amendments, of one or many tuples.

12 Slide 12 Example : a Circular Referential Path Suppose a DB contains 3 relations : Details about projects for departments. Details about locations, including its project. PROJECT( ProjNo, DeptID,.. ) LOCATION( Loc, ProjNo,.. ) Each relation has a foreign key that references another relation, so they are linked circularly. DEPARTMENT( Loc, DeptID,. ) Details about departments, including their location. The PROJECT relation has a foreign key DeptID that references the DEPARTMENT relation. The DEPARTMENT relation has a foreign key Loc that references the LOCATION relation. The LOCATION relation has a foreign key ProjNo that references the PROJECT relation. Thus if there are any updates involving projects for departments in locations, it is likely that all three relations will have to be updated. In this case, it will not even be possible to derive a particular order for updating that will avoid the referential integrity problem, due to the circularity. All three will have to be appropriately updated, and then the validity checks carried out to ensure integrity constraints are maintained.

13 Slide 13 Example Transaction with Circularity The 3 relations are shown as tables, with the corresponding referencing and referenced attributes. Update PROJECT Update DEPARTMENT Update LOCATION Transaction BEGIN Integrity can only be checked at the transaction s end. Transaction END In principle, it doesn t matter which relation is updated first, or which route round the circle is taken - a circle has no end! - although pragmatic considerations might suggest certain starting points and directions.

14 Slide 14 Timing of Integrity Checks Thus integrity checks can be split into 2 classes, immediate and deferred. Immediate integrity checks should be done as soon as the update is completed. There is no point in waiting to complete the transaction. As soon as an error is found, the transaction can be terminated without wasting any more time and processing. Deferred integrity checks must be done by the end of the transaction. They are typically done at the end of the transaction. The transaction must be designed so that the updates put the DB in the correct state by the end of the transaction. SQL follows these ideas of transactions and integrity checking, as we will see next, although SQL s integrity checking is a little more complex than this. There are other aspects of transactions to do with solving the problems of multiple users trying to update the same data at the same time, but they are beyond the scope of this course.

15 Slide 15 SQL Transactions A transaction automatically starts whenever the first SQL Insert / Delete / Update statement is met. There is no special command to start a transaction. More Insert / Delete / Update statements, or none, may follow in the transaction. A transaction ends when a Commit or Rollback statement is met. Commit ; Ensures any deferred checks are executed; if there are no integrity errors, it makes the updates permanent. Rollback : Undoes all the updates to return the DB to its state at the beginning of the transaction. Thus a simple transaction may look like : Insert Commit ; A more complex transaction may look like : Insert Update Insert Delete Commit ; If at the end of a transaction the integrity constraints are not satisfied, as well as issuing an error message, the Commit statement will roll back the transaction if any insert, delete and/or update statements have already been successfully executed during the transaction, so that the DB returns to the state it was in at the beginning of the transaction. Rollback is important generally for correcting mistakes made in updating. Oracle does have a Set Transaction statement that can be used to initiate a transaction, although that is not its prime raison d etre (which is, via various possible parameters, to manage the transaction in other ways, beyond the scope of this course).

16 Slide 16 Deferrability of SQL Checks In SQL, integrity constraints are deferrable or not deferrable. Not deferrable constraints are checked immediately. Deferrable constraints are further defined to be : Initially deferred - not checked until a Commit statement is reached. Initially immediate - checked immediately. Deferrable constraints can be switched between these two, using the Set Constraint statement. Examples : Set Constraint FKEY1, FKEY9 Deferred ; Set Constraint PKEY6 Immediate; When an integrity constraint is assigned, it will be one of : not deferrable, i.e. immediate, deferrable, and set to be deferred to start with (i.e. initially), deferrable, but set to be immediate to start with (i.e. initially). The keywords for these three possibilities are : Not Deferrable, Deferrable Initially Deferred, Deferrable Initially Immediate. Put the required keywords immediately after the constraint definition. For example : Constraint PKEY6 Primary Key( ID ) Not Deferrable Not Deferrable is the default; so all constraints seen in slides so far will be immediately checked. After the initial setting of a deferrable constraint, the Set Constraint statement can be used at any time thereafter to switch it between immediate checking and defer-to- Commit-time checking. Note that Set Constraint uses an integrity constraint name or the keyword All to reference constraints, and can only be applied to deferrable constraints. The Set Constraint statement can be issued at any point in a transaction, and remains in force until the end of the transaction or until superseded by another Set Constraint statement.

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

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

Database Modelling. Lecture 4 (b): Database Integrity, Keys & Constraints. Akhtar Ali 10/14/2014 1 Database Modelling Lecture 4 (b): Database Integrity, Keys & Constraints Akhtar Ali 10/14/2014 1 Learning Objectives 1. To consider Referential Integrity & Foreign Keys 2. To consider Referential Integrity

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

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

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

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

Examples of Relational Value Assignments

Examples of Relational Value Assignments Examples of Relational Value Assignments Example Relvars - First Set Let relvar EMP contain sample data of the ID number and name of employees, displayed in tabular format as :- No Name 1 Jack 2 Jill Example

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

Chapter 2 Introduction to Relational Models

Chapter 2 Introduction to Relational Models CMSC 461, Database Management Systems Spring 2018 Chapter 2 Introduction to Relational Models These slides are based on Database System Concepts book and slides, 6th edition, and the 2009 CMSC 461 slides

More information

School of Computing, Engineering and Information Sciences University of Northumbria. Set Operations

School of Computing, Engineering and Information Sciences University of Northumbria. Set Operations Set Operations Aim: To understand how to do the equivalent of the UNION, DIFFERENCE and INTERSECT set operations in SQL. Outline of Session: Do some example SQL queries to learn to differentiate between

More information

Lab IV. Transaction Management. Database Laboratory

Lab IV. Transaction Management. Database Laboratory Lab IV Transaction Management Database Laboratory Objectives To work with transactions in ORACLE To study the properties of transactions in ORACLE Database integrity must be controlled when access operations

More information

SQL: A COMMERCIAL DATABASE LANGUAGE. Complex Constraints

SQL: A COMMERCIAL DATABASE LANGUAGE. Complex Constraints SQL: A COMMERCIAL DATABASE LANGUAGE Complex Constraints Outline 1. Introduction 2. Data Definition, Basic Constraints, and Schema Changes 3. Basic Queries 4. More complex Queries 5. Aggregate Functions

More information

SQL Interview Questions

SQL Interview Questions SQL Interview Questions SQL stands for Structured Query Language. It is used as a programming language for querying Relational Database Management Systems. In this tutorial, we shall go through the basic

More information

Introduction to Databases, Fall 2005 IT University of Copenhagen. Lecture 10: Transaction processing. November 14, Lecturer: Rasmus Pagh

Introduction to Databases, Fall 2005 IT University of Copenhagen. Lecture 10: Transaction processing. November 14, Lecturer: Rasmus Pagh Introduction to Databases, Fall 2005 IT University of Copenhagen Lecture 10: Transaction processing November 14, 2005 Lecturer: Rasmus Pagh Today s lecture Part I: Transaction processing Serializability

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

Active Databases Part 1: Introduction CS561

Active Databases Part 1: Introduction CS561 Active Databases Part 1: Introduction CS561 1 Active Databases n Triggers and rules are developed for data integrity and constraints n Triggers make passive database active Database reacts to certain situations

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

Database Management System 9

Database Management System 9 Database Management System 9 School of Computer Engineering, KIIT University 9.1 Relational data model is the primary data model for commercial data- processing applications A relational database consists

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

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

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. # 5 Structured Query Language Hello and greetings. In the ongoing

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

Intermediate SQL ( )

Intermediate SQL ( ) CSL 451 Introduction to Database Systems Intermediate SQL (4.1-4.4) Department of Computer Science and Engineering Indian Institute of Technology Ropar Narayanan (CK) Chatapuram Krishnan! Summary Join

More information

We shall represent a relation as a table with columns and rows. Each column of the table has a name, or attribute. Each row is called a tuple.

We shall represent a relation as a table with columns and rows. Each column of the table has a name, or attribute. Each row is called a tuple. Logical Database design Earlier we saw how to convert an unorganized text description of information requirements into a conceptual design, by the use of ER diagrams. The advantage of ER diagrams is that

More information

Interview Questions on DBMS and SQL [Compiled by M V Kamal, Associate Professor, CSE Dept]

Interview Questions on DBMS and SQL [Compiled by M V Kamal, Associate Professor, CSE Dept] Interview Questions on DBMS and SQL [Compiled by M V Kamal, Associate Professor, CSE Dept] 1. What is DBMS? A Database Management System (DBMS) is a program that controls creation, maintenance and use

More information

Chapter 2: Intro to Relational Model

Chapter 2: Intro to Relational Model Chapter 2: Intro to Relational Model Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Example of a Relation attributes (or columns) tuples (or rows) 2.2 Attribute Types The

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

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

Department of Computer Science and Information Systems, College of Business and Technology, Morehead State University

Department of Computer Science and Information Systems, College of Business and Technology, Morehead State University 1 Department of Computer Science and Information Systems, College of Business and Technology, Morehead State University Lecture 3 Part A CIS 311 Introduction to Management Information Systems (Spring 2017)

More information

Databases. Relational Model, Algebra and operations. How do we model and manipulate complex data structures inside a computer system? Until

Databases. Relational Model, Algebra and operations. How do we model and manipulate complex data structures inside a computer system? Until Databases Relational Model, Algebra and operations How do we model and manipulate complex data structures inside a computer system? Until 1970.. Many different views or ways of doing this Could use tree

More information

Outer Join, More on SQL Constraints

Outer Join, More on SQL Constraints Outer Join, More on SQL Constraints CS430/630 Lecture 10 Slides based on Database Management Systems 3 rd ed, Ramakrishnan and Gehrke Outer Joins Include in join result non-matching tuples Result tuple

More information

RAQUEL s Relational Operators

RAQUEL s Relational Operators Contents RAQUEL s Relational Operators Introduction 2 General Principles 2 Operator Parameters 3 Ordinary & High-Level Operators 3 Operator Valency 4 Default Tuples 5 The Relational Algebra Operators in

More information

COSC344 Database Theory and Applications. Lecture 21 Transactions

COSC344 Database Theory and Applications. Lecture 21 Transactions COSC344 Database Theory and Applications Lecture 21 Transactions - Overview This Lecture Transactions Source: Chapter 20 Next Lecture Concurrency control Source: Chapter 21 Lecture After Recovery Source:

More information

Overview. Data Integrity. Three basic types of data integrity. Integrity implementation and enforcement. Database constraints Transaction Trigger

Overview. Data Integrity. Three basic types of data integrity. Integrity implementation and enforcement. Database constraints Transaction Trigger Data Integrity IT 4153 Advanced Database J.G. Zheng Spring 2012 Overview Three basic types of data integrity Integrity implementation and enforcement Database constraints Transaction Trigger 2 1 Data Integrity

More information

Q.1 Short Questions Marks 1. New fields can be added to the created table by using command. a) ALTER b) SELECT c) CREATE. D. UPDATE.

Q.1 Short Questions Marks 1. New fields can be added to the created table by using command. a) ALTER b) SELECT c) CREATE. D. UPDATE. ID No. Knowledge Institute of Technology & Engineering - 135 BE III SEMESTER MID EXAMINATION ( SEPT-27) PAPER SOLUTION Subject Code: 2130703 Date: 14/09/27 Subject Name: Database Management Systems Branches:

More information

Database Management Systems Paper Solution

Database Management Systems Paper Solution Database Management Systems Paper Solution Following questions have been asked in GATE CS exam. 1. Given the relations employee (name, salary, deptno) and department (deptno, deptname, address) Which of

More information

CS2 Current Technologies Note 1 CS2Bh

CS2 Current Technologies Note 1 CS2Bh CS2 Current Technologies Note 1 Relational Database Systems Introduction When we wish to extract information from a database, we communicate with the Database Management System (DBMS) using a query language

More information

Database Technology. Topic 11: Database Recovery

Database Technology. Topic 11: Database Recovery Topic 11: Database Recovery Olaf Hartig olaf.hartig@liu.se Types of Failures Database may become unavailable for use due to: Transaction failures e.g., incorrect input, deadlock, incorrect synchronization

More information

Essay Question: Explain 4 different means by which constrains are represented in the Conceptual Data Model (CDM).

Essay Question: Explain 4 different means by which constrains are represented in the Conceptual Data Model (CDM). Question 1 Essay Question: Explain 4 different means by which constrains are represented in the Conceptual Data Model (CDM). By specifying participation conditions By specifying the degree of relationship

More information

COURSE OVERVIEW THE RELATIONAL MODEL. CS121: Relational Databases Fall 2017 Lecture 1

COURSE OVERVIEW THE RELATIONAL MODEL. CS121: Relational Databases Fall 2017 Lecture 1 COURSE OVERVIEW THE RELATIONAL MODEL CS121: Relational Databases Fall 2017 Lecture 1 Course Overview 2 Introduction to relational database systems Theory and use of relational databases Focus on: The Relational

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

COURSE OVERVIEW THE RELATIONAL MODEL. CS121: Introduction to Relational Database Systems Fall 2016 Lecture 1

COURSE OVERVIEW THE RELATIONAL MODEL. CS121: Introduction to Relational Database Systems Fall 2016 Lecture 1 COURSE OVERVIEW THE RELATIONAL MODEL CS121: Introduction to Relational Database Systems Fall 2016 Lecture 1 Course Overview 2 Introduction to relational database systems Theory and use of relational databases

More information

8) A top-to-bottom relationship among the items in a database is established by a

8) A top-to-bottom relationship among the items in a database is established by a MULTIPLE CHOICE QUESTIONS IN DBMS (unit-1 to unit-4) 1) ER model is used in phase a) conceptual database b) schema refinement c) physical refinement d) applications and security 2) The ER model is relevant

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

Relational Algebra for sets Introduction to relational algebra for bags

Relational Algebra for sets Introduction to relational algebra for bags Relational Algebra for sets Introduction to relational algebra for bags Thursday, September 27, 2012 1 1 Terminology for Relational Databases Slide repeated from Lecture 1... Account Number Owner Balance

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

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

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

Schedule. Today: Feb. 21 (TH) Feb. 28 (TH) Feb. 26 (T) Mar. 5 (T) Read Sections , Project Part 6 due.

Schedule. Today: Feb. 21 (TH) Feb. 28 (TH) Feb. 26 (T) Mar. 5 (T) Read Sections , Project Part 6 due. Schedule Today: Feb. 21 (TH) Transactions, Authorization. Read Sections 8.6-8.7. Project Part 5 due. Feb. 26 (T) Datalog. Read Sections 10.1-10.2. Assignment 6 due. Feb. 28 (TH) Datalog and SQL Recursion,

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

SQL DDL. CS3 Database Systems Weeks 4-5 SQL DDL Database design. Key Constraints. Inclusion Constraints

SQL DDL. CS3 Database Systems Weeks 4-5 SQL DDL Database design. Key Constraints. Inclusion Constraints SQL DDL CS3 Database Systems Weeks 4-5 SQL DDL Database design In its simplest use, SQL s Data Definition Language (DDL) provides a name and a type for each column of a table. CREATE TABLE Hikers ( HId

More information

SQL Constraints and Triggers. Week 11

SQL Constraints and Triggers. Week 11 SQL Constraints and Triggers Week 11 1 SQL Constraints Constraints Primary Key (covered) Foreign Key (covered) General table constraints Domain constraints Assertions Triggers General Constraints A general

More information

Recoverability. Kathleen Durant PhD CS3200

Recoverability. Kathleen Durant PhD CS3200 Recoverability Kathleen Durant PhD CS3200 1 Recovery Manager Recovery manager ensures the ACID principles of atomicity and durability Atomicity: either all actions in a transaction are done or none are

More information

3.1. Keys: Super Key, Candidate Key, Primary Key, Alternate Key, Foreign Key

3.1. Keys: Super Key, Candidate Key, Primary Key, Alternate Key, Foreign Key Unit 3: Types of Keys & Data Integrity 3.1. Keys: Super Key, Candidate Key, Primary Key, Alternate Key, Foreign Key Different Types of SQL Keys A key is a single or combination of multiple fields in a

More information

Database Systems Relational Model. A.R. Hurson 323 CS Building

Database Systems Relational Model. A.R. Hurson 323 CS Building Relational Model A.R. Hurson 323 CS Building Relational data model Database is represented by a set of tables (relations), in which a row (tuple) represents an entity (object, record) and a column corresponds

More information

Chapter 2. DB2 concepts

Chapter 2. DB2 concepts 4960ch02qxd 10/6/2000 7:20 AM Page 37 DB2 concepts Chapter 2 Structured query language 38 DB2 data structures 40 Enforcing business rules 49 DB2 system structures 52 Application processes and transactions

More information

Introduction to Relational Databases. Introduction to Relational Databases cont: Introduction to Relational Databases cont: Relational Data structure

Introduction to Relational Databases. Introduction to Relational Databases cont: Introduction to Relational Databases cont: Relational Data structure Databases databases Terminology of relational model Properties of database relations. Relational Keys. Meaning of entity integrity and referential integrity. Purpose and advantages of views. The relational

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

download instant at The Relational Data Model

download instant at  The Relational Data Model 3 The Relational Data Model EXERCISES 3.1 Define data atomicity as it relates to the definition of relational databases. Contrast data atomicity with transaction atomicity as used in a transaction processing

More information

Database Recovery. Dr. Bassam Hammo

Database Recovery. Dr. Bassam Hammo Database Recovery Dr. Bassam Hammo 1 Transaction Concept A transaction is a unit of execution Either committed or aborted. After a transaction, the db must be consistent. Consistent No violation of any

More information

CSC 742 Database Management Systems

CSC 742 Database Management Systems CSC 742 Database Management Systems Topic #5: Relational Model Spring 2002 CSC 742: DBMS by Dr. Peng Ning 1 Motivation A relation is a mathematical abstraction for a table The theory of relations provides

More information

Databases. Jörg Endrullis. VU University Amsterdam

Databases. Jörg Endrullis. VU University Amsterdam Databases Jörg Endrullis VU University Amsterdam The Relational Model Overview 1. Relational Model Concepts: Schema, State 2. Null Values 3. Constraints: General Remarks 4. Key Constraints 5. Foreign Key

More information

Enhanced Data Models for Advanced Applications. Active Database Concepts

Enhanced Data Models for Advanced Applications. Active Database Concepts Enhanced Data Models for Advanced Applications Active Database Concepts Topics To Be Discussed Generalized Model for Active Databases and Oracle Triggers Design and Implementation Issues for Active Databases

More information

Lesson 14 Transcript: Triggers

Lesson 14 Transcript: Triggers Lesson 14 Transcript: Triggers Slide 1: Cover Welcome to Lesson 14 of DB2 on Campus Lecture Series. Today, we are going to talk about Triggers. My name is Raul Chong, and I'm the DB2 on Campus Program

More information

CSE 132A Database Systems Principles

CSE 132A Database Systems Principles CSE 132A Database Systems Principles Prof. Alin Deutsch RELATIONAL DATA MODEL Some slides are based or modified from originals by Elmasri and Navathe, Fundamentals of Database Systems, 4th Edition 2004

More information

Introduction to Database Systems. Announcements CSE 444. Review: Closure, Key, Superkey. Decomposition: Schema Design using FD

Introduction to Database Systems. Announcements CSE 444. Review: Closure, Key, Superkey. Decomposition: Schema Design using FD Introduction to Database Systems CSE 444 Lecture #9 Jan 29 2001 Announcements Mid Term on Monday (in class) Material in lectures Textbook Chapter 1.1, Chapter 2 (except 2.1 and ODL), Chapter 3 (except

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

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

CSCU9Q5. Topic Overview. Transaction Management. The Concept of a Transaction BACKUP & CONCURRENCY. CSCU9Q5: Database P&A 14 November 2017

CSCU9Q5. Topic Overview. Transaction Management. The Concept of a Transaction BACKUP & CONCURRENCY. CSCU9Q5: Database P&A 14 November 2017 Topic Overview CSCU9Q5 BACKUP & CONCURRENCY A DBMS must ensure that the database is reliable and remains in a consistent state. This reliability and consistency must be maintained in the presence of failures

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

Integrity and Security

Integrity and Security C H A P T E R 6 Integrity and Security This chapter presents several types of integrity constraints, including domain constraints, referential integrity constraints, assertions and triggers, as well as

More information

Database Management System (15ECSC208) UNIT I: Chapter 2: Relational Data Model and Relational Algebra

Database Management System (15ECSC208) UNIT I: Chapter 2: Relational Data Model and Relational Algebra Database Management System (15ECSC208) UNIT I: Chapter 2: Relational Data Model and Relational Algebra Relational Data Model and Relational Constraints Part 1 A simplified diagram to illustrate the main

More information

CS W Introduction to Databases Spring Computer Science Department Columbia University

CS W Introduction to Databases Spring Computer Science Department Columbia University CS W4111.001 Introduction to Databases Spring 2018 Computer Science Department Columbia University 1 in SQL 1. Key constraints (PRIMARY KEY and UNIQUE) 2. Referential integrity constraints (FOREIGN KEY

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

Data Manipulation (DML) and Data Definition (DDL)

Data Manipulation (DML) and Data Definition (DDL) Data Manipulation (DML) and Data Definition (DDL) 114 SQL-DML Inserting Tuples INSERT INTO REGION VALUES (6,'Antarctica','') INSERT INTO NATION (N_NATIONKEY, N_NAME, N_REGIONKEY) SELECT NATIONKEY, NAME,

More information

Normalization in DBMS

Normalization in DBMS Unit 4: Normalization 4.1. Need of Normalization (Consequences of Bad Design-Insert, Update & Delete Anomalies) 4.2. Normalization 4.2.1. First Normal Form 4.2.2. Second Normal Form 4.2.3. Third Normal

More information

Sankalchand Patel College of Engineering, Visnagar B.E. Semester III (CE/IT) Database Management System Question Bank / Assignment

Sankalchand Patel College of Engineering, Visnagar B.E. Semester III (CE/IT) Database Management System Question Bank / Assignment Sankalchand Patel College of Engineering, Visnagar B.E. Semester III (CE/IT) Database Management System Question Bank / Assignment Introductory concepts of DBMS 1. Explain detailed 3-level architecture

More information

CSC 261/461 Database Systems Lecture 6. Fall 2017

CSC 261/461 Database Systems Lecture 6. Fall 2017 CSC 261/461 Database Systems Lecture 6 Fall 2017 Use of WITH The WITH clause allows a user to define a table that will only be used in a particular query (not available in all SQL implementations) Used

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

Chapter 6: Relational Database Design

Chapter 6: Relational Database Design Chapter 6: Relational Database Design Chapter 6: Relational Database Design Features of Good Relational Design Atomic Domains and First Normal Form Decomposition Using Functional Dependencies Second Normal

More information

DBMS. Relational Model. Module Title?

DBMS. Relational Model. Module Title? Relational Model Why Study the Relational Model? Most widely used model currently. DB2,, MySQL, Oracle, PostgreSQL, SQLServer, Note: some Legacy systems use older models e.g., IBM s IMS Object-oriented

More information

In mathematical terms, the relation itself can be expressed simply in terms of the attributes it contains:

In mathematical terms, the relation itself can be expressed simply in terms of the attributes it contains: The Relational Model The relational data model organises data as 2-dimensional tables or relations. An example of one such relation would be STUDENT shown below. As we have seen in the wine list example,

More information

Chapter 4: Intermediate SQL

Chapter 4: Intermediate SQL Chapter 4: Intermediate SQL Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use 4.1 Join Expressions Let s first review the joins from ch.3 4.2 1 SELECT * FROM student, takes

More information

Illustrative Example of Physical Schema Usage

Illustrative Example of Physical Schema Usage Example of Physical Usage 14 th February 2014 (30 th March 2001) Illustrative Example of Physical Usage The example assumes that a small RAQUEL DB and its relational model schemas have already been created.

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

Mapping ER Diagrams to. Relations (Cont d) Mapping ER Diagrams to. Exercise. Relations. Mapping ER Diagrams to Relations (Cont d) Exercise

Mapping ER Diagrams to. Relations (Cont d) Mapping ER Diagrams to. Exercise. Relations. Mapping ER Diagrams to Relations (Cont d) Exercise CSC 74 Database Management Systems Topic #6: Database Design Weak Entity Type E Create a relation R Include all simple attributes and simple components of composite attributes. Include the primary key

More information

Constraints, Views & Indexes. Running Example. Kinds of Constraints INTEGRITY CONSTRAINTS. Keys Foreign key or referential integrity constraints

Constraints, Views & Indexes. Running Example. Kinds of Constraints INTEGRITY CONSTRAINTS. Keys Foreign key or referential integrity constraints 2 Constraints, Views & Indexes Introduction to databases CSCC43 Winter 2012 Ryan Johnson INTEGRITY CONSTRAINTS Thanks to Manos Papagelis, John Mylopoulos, Arnold Rosenbloom and Renee Miller for material

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. # 3 Relational Model Hello everyone, we have been looking into

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

Techno India Batanagar Computer Science and Engineering. Model Questions. Subject Name: Database Management System Subject Code: CS 601

Techno India Batanagar Computer Science and Engineering. Model Questions. Subject Name: Database Management System Subject Code: CS 601 Techno India Batanagar Computer Science and Engineering Model Questions Subject Name: Database Management System Subject Code: CS 601 Multiple Choice Type Questions 1. Data structure or the data stored

More information

Relational Model History. COSC 304 Introduction to Database Systems. Relational Model and Algebra. Relational Model Definitions.

Relational Model History. COSC 304 Introduction to Database Systems. Relational Model and Algebra. Relational Model Definitions. COSC 304 Introduction to Database Systems Relational Model and Algebra Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca Relational Model History The relational model was

More information

Stored Relvars 18 th April 2013 (30 th March 2001) David Livingstone. Stored Relvars

Stored Relvars 18 th April 2013 (30 th March 2001) David Livingstone. Stored Relvars Stored Relvars Introduction The purpose of a Stored Relvar (= Stored Relational Variable) is to provide a mechanism by which the value of a real (or base) relvar may be partitioned into fragments and/or

More information

Database Management System

Database Management System Database Management System Lecture 10 Recovery * Some materials adapted from R. Ramakrishnan, J. Gehrke and Shawn Bowers Basic Database Architecture Database Management System 2 Recovery Which ACID properties

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

The Relational Data Model and Relational Database Constraints

The Relational Data Model and Relational Database Constraints CHAPTER 5 The Relational Data Model and Relational Database Constraints Copyright 2017 Ramez Elmasri and Shamkant B. Navathe Slide 1-2 Chapter Outline Relational Model Concepts Relational Model Constraints

More information

SQL. History. From Wikipedia, the free encyclopedia.

SQL. History. From Wikipedia, the free encyclopedia. SQL From Wikipedia, the free encyclopedia. Structured Query Language (SQL) is the most popular computer language used to create, modify and retrieve data from relational database management systems. The

More information

Database Management Systems

Database Management Systems S.Y. B.Sc. (IT) : Sem. III Database Management Systems Time : 2½ Hrs.] Prelim Question Paper Solution [Marks : 75 Q.1 Attempt the following (any THREE) [15] Q.1 (a) Explain database system and give its

More information

Managing Data. Copyright 2004, Oracle. All rights reserved.

Managing Data. Copyright 2004, Oracle. All rights reserved. Managing Data Objectives After completing this lesson, you should be able to do the following: Manipulate data through SQL Use Data Pump to export data Use Data Pump to import data Load data with SQL Loader

More information

Chapter 2: Relational Model

Chapter 2: Relational Model Chapter 2: Relational Model Database System Concepts, 5 th Ed. See www.db-book.com for conditions on re-use Chapter 2: Relational Model Structure of Relational Databases Fundamental Relational-Algebra-Operations

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