Daffodil DB. Design Document (Beta) Version 4.0

Similar documents
Chapter 1 SQL and Data

GridDB Advanced Edition SQL reference

EGCI 321: Database Systems. Dr. Tanasanee Phienthrakul

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

M.C.A. (CBCS) Sem.-III Examination November-2013 CCA-3004 : Database Concepts and Tools. Faculty Code: 003 Subject Code:

Today Learning outcomes LO2

Chapter 4. Basic SQL. Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

SQL: Data De ni on. B0B36DBS, BD6B36DBS: Database Systems. h p:// Lecture 3

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

Information Systems Engineering. SQL Structured Query Language DDL Data Definition (sub)language

THE UNIVERSITY OF AUCKLAND

Chapter # 7 Introduction to Structured Query Language (SQL) Part I

Introduction to Computer Science and Business

Data Modelling and Databases. Exercise Session 7: Integrity Constraints

COMP 3400 Mainframe Administration 1

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

1 Prepared By Heena Patel (Asst. Prof)

Lab # 2. Data Definition Language (DDL) Eng. Alaa O Shama

Chapter 4. Basic SQL. SQL Data Definition and Data Types. Basic SQL. SQL language SQL. Terminology: CREATE statement

A7-R3: INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS

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

COMP 430 Intro. to Database Systems

SQL Interview Questions

Sql Server Syllabus. Overview

Where are we? Week -4: Data definition (Creation of the schema) Week -3: Data definition (Triggers) Week -1: Transactions and concurrency in ORACLE.

Lab # 4. Data Definition Language (DDL)

SQL: Data Definition Language. csc343, Introduction to Databases Diane Horton Fall 2017

Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications. Today's Party. Example Database. Faloutsos/Pavlo CMU /615

Introduction The SELECT statement: basics Nested queries Set operators Update commands Table management

II B.Sc(IT) [ BATCH] IV SEMESTER CORE: RELATIONAL DATABASE MANAGEMENT SYSTEM - 412A Multiple Choice Questions.

GridDB Advanced Edition SQL reference

Oracle SQL Developer. Oracle TimesTen In-Memory Database Support User's Guide Release 4.0 E

Announcements (September 18) SQL: Part II. Solution 1. Incomplete information. Solution 3? Solution 2. Homework #1 due today (11:59pm)

Essential SQLite3. Section Title Page

INTRODUCTION TO DATABASE

Content: How to transform the relational model into a database schema DDL: create table students(studentnr int, name varchar);

SQL Fundamentals. Chapter 3. Class 03: SQL Fundamentals 1

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Carnegie Mellon Univ. Dept. of Computer Science Database Applications. General Overview - rel. model. Overview - detailed - SQL

Embedded SQL Guide. Borland InterBase VERSION 7.5. Borland Software Corporation 100 Enterprise Way, Scotts Valley, CA

Principles of Data Management

IBM DB2 UDB V7.1 Family Fundamentals.

"Charting the Course to Your Success!" MOC D Querying Microsoft SQL Server Course Summary

DB Creation with SQL DDL

INFORMATION TECHNOLOGY NOTES

Review -Chapter 4. Review -Chapter 5

Efficient Object-Relational Mapping for JAVA and J2EE Applications or the impact of J2EE on RDB. Marc Stampfli Oracle Software (Switzerland) Ltd.

SQL: Part II. Announcements (September 18) Incomplete information. CPS 116 Introduction to Database Systems. Homework #1 due today (11:59pm)

Working with DB2 Data Using SQL and XQuery Answers

B.H.GARDI COLLEGE OF MASTER OF COMPUTER APPLICATION. Ch. 1 :- Introduction Database Management System - 1

Oracle Database 11g: SQL and PL/SQL Fundamentals

CMPT 354: Database System I. Lecture 2. Relational Model

SQL: Data Definition Language

Index. Bitmap Heap Scan, 156 Bitmap Index Scan, 156. Rahul Batra 2018 R. Batra, SQL Primer,

MTAT Introduction to Databases

IBM Database Conversion Workbench 3.5

SQL Data Definition and Data Manipulation Languages (DDL and DML)

C Examcollection.Premium.Exam.58q

2.9 Table Creation. CREATE TABLE TableName ( AttrName AttrType, AttrName AttrType,... )

Model Question Paper. Credits: 4 Marks: 140

Basic SQL. Basic SQL. Basic SQL

The Relational Model of Data (ii)

CS448 Designing and Implementing a Mini Relational DBMS

Database Management Systems. Chapter 3 Part 1

Project # 1: Database Programming

AO3 - Version: 2. Oracle Database 11g SQL

Lecture 2: Introduction to SQL

Difficult I.Q on Databases, asked to SCTPL level 2 students 2015

Constraints. Primary Key Foreign Key General table constraints Domain constraints Assertions Triggers. John Edgar 2

Introduction to SQL Part 1 By Michael Hahsler based on slides for CS145 Introduction to Databases (Stanford)

SQL+PL/SQL. Introduction to SQL

Real Application Security Administration

SQL DATA DEFINITION LANGUAGE

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

Midterm Review. Winter Lecture 13

IBM EXAM QUESTIONS & ANSWERS

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

Creating and Managing Tables Schedule: Timing Topic

Chapter-14 SQL COMMANDS

ADVANTAGES. Via PL/SQL, all sorts of calculations can be done quickly and efficiently without use of Oracle engine.

Cloudscape Synchronization Guide

Announcements. SQL: Part IV. Transactions. Summary of SQL features covered so far. Fine prints. SQL transactions. Reading assignments for this week

JDO XML MetaData Reference (v5.2)

E-R diagrams and database schemas. Functional dependencies. Definition (tuple, attribute, value). A tuple has the form

CS6312 DATABASE MANAGEMENT SYSTEMS LABORATORY L T P C

UNIT 4 DATABASE SYSTEM CATALOGUE

SQL DATA DEFINITION LANGUAGE

Question: Which statement would you use to invoke a stored procedure in isql*plus?


Review. The Relational Model. Glossary. Review. Data Models. Why Study the Relational Model? Why use a DBMS? OS provides RAM and disk

SQL: Part III. Announcements. Constraints. CPS 216 Advanced Database Systems

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

Pro JPA 2. Mastering the Java Persistence API. Apress* Mike Keith and Merrick Schnicariol

1) Introduction to SQL

Lecture 08. Spring 2018 Borough of Manhattan Community College

SQL is an English like language consisting of commands to store, retrieve, maintain & regulate access to your database.

Data! CS 133: Databases. Goals for Today. So, what is a database? What is a database anyway? From the textbook:

TINYINT[(M)] [UNSIGNED] [ZEROFILL] A very small integer. The signed range is -128 to 127. The unsigned range is 0 to 255.

SQL DATA DEFINITION LANGUAGE

How to define a relational schema for a data base?

Transcription:

Daffodil DB Design Document (Beta) Version 4.0 January 2005

Copyright Daffodil Software Limited Sco 42,3 rd Floor Old Judicial Complex, Civil lines Gurgaon - 122001 Haryana, India. www.daffodildb.com All rights reserved. Daffodil DB is a registered trademark of Daffodil Software Limited. Java is a registered trademark of Sun Microsystems, Inc. All other brand and product names are trademarks of their respective companies. Copyright 2005 Daffodil Software Ltd. 2

Table of Contents TABLE OF FIGURES... 5 PREFACE... 7 PURPOSE... 7 TARGET AUDIENCE... 8 PRE-REQUISITES... 9 TOP LEVEL INTERACTION DIAGRAMS... 10 EXECUTE DDL QUERY... 11 EXECUTE DML QUERY... 13 EXECUTE DQL QUERY... 15 JDBC DRIVER... 17 SERVER...18 OVERVIEW... 18 SERVERSYSTEM... 19 DML... 21 OVERVIEW... 21 CONSTRAINTSYSTEM... 75 TRIGGERSYSTEM... 79 SQL... 82 DDL... 85 OVERVIEW... 85 SQL... 95 DESCRIPTORS... 101 DQL... 105 OVERVIEW... 105 SQL... 146 NAVIGATOR... 149 EXECUTIONPLAN... 153 SESSION... 156 OVERVIEW... 156 SESSIONSYSTEM... 170 DATADICTIONARY... 177 DATA STORE... 182 OVERVIEW... 182 FILESYSTEM... 199 INDEXSYSTEM... 205 Copyright 2005 Daffodil Software Ltd. 3

PARSER... 210 OVERVIEW... 210 PARSER SYSTEM... 215 RELATED DOCUMENTATION... 218 SIGN UP FOR SUPPORT... 219 WE NEED FEEDBACK!... 220 LICENSE NOTICE... 221 Copyright 2005 Daffodil Software Ltd. 4

Table of Figures FIGURE 1: TOP LEVEL INTERACTION DIAGRAM... 10 FIGURE 2: INTERACTION DIAGRAM - EXECUTE DDL QUERY... 11 FIGURE 3: INTERACTION DIAGRAM - EXECUTE DML QUERY... 13 FIGURE 4: INTERACTION DIAGRAM - EXECUTE DQL QUERY... 15 FIGURE 5: CLASS DIAGRAM - SERVERSYSTEM... 19 FIGURE 6: INTERACTION DIAGRAM - EXECUTE INSERT QUERY... 67 FIGURE 7: INTERACTION DIAGRAM - EXECUTE UPDATE QUERY... 68 FIGURE 8: INTERACTION DIAGRAM - EXECUTE DELETE QUERY... 70 FIGURE 9: INTERACTION DIAGRAM - CONSTRAINT CHECKING... 72 FIGURE 10: INTERACTION DIAGRAM - TRIGGER EXECUTION... 74 FIGURE 11: CLASS DIAGRAM - CONSTRAINTSYSTEM ( INTERFACES)... 75 FIGURE 12: CLASS DIAGRAM - CONSTRAINTSYSTEM (CLASSES)... 76 FIGURE 13: CLASS DIAGRAM - TRIGGERSYSTEM (INTERFACES)... 79 FIGURE 14: CLASS DIAGRAM - TRIGGERSYSTEM (CLASSES)... 80 FIGURE 15: CLASS DIAGRAM - SQL (DML)... 82 FIGURE 16: INTERACTION DIAGRAM - CREATION OF OBJECT... 87 FIGURE 17: INTERACTION DIAGRAM - DROPPING OF OBJECT... 89 FIGURE 18: INTERACTION DIAGRAM - GRANT USER PRIVILEGES... 91 FIGURE 19: INTERACTION DIAGRAM - REVOKE USER PRIVILEGES... 92 FIGURE 20: INTERACTION DIAGRAM - CHECK SEMANTIC... 93 FIGURE 21: CLASS DIAGRAM - SQL (DDL)... 95 FIGURE 22: CLASS DIAGRAM - DESCRIPTORS... 101 FIGURE 23: INTERACTION DIAGRAM - EXECUTE SIMPLE QUERY... 129 FIGURE 24: INTERACTION DIAGRAM - EXECUTE QUERY INVOLVING JOINS... 132 FIGURE 25: INTERACTION DIAGRAM - EXECUTE QUERY WITH GROUP BY CLAUSE... 134 FIGURE 26: INTERACTION DIAGRAM - EXECUTE QUERY INVOLVING SET OPERATORS... 138 FIGURE 27: INTERACTION DIAGRAM - EXECUTE QUERY WITH ORDER BY CLAUSE... 140 FIGURE 28: INTERACTION DIAGRAM - EXECUTE QUERY INVOLVING SUB-QUERY... 142 FIGURE 29: INTERACTION DIAGRAM - EXECUTE QUERY INVOLVING VIEW... 144 FIGURE 30: CLASS DIAGRAM - SQL (DQL)... 146 FIGURE 31: CLASS DIAGRAM - NAVIGATOR... 149 FIGURE 32: CLASS DIAGRAM - EXECUTION PLAN... 153 FIGURE 33: INTERACTION DIAGRAM - RECORD LOCKING... 166 FIGURE 34: INTERACTION DIAGRAM - TRANSACTION COMMIT... 167 FIGURE 35: INTERACTION DIAGRAM - READ COMMITTED ISOLATION LEVEL... 168 FIGURE 36: INTERACTION DIAGRAM - GET META DATA INFO... 169 FIGURE 37: CLASS DIAGRAM SESSIONSYSTEM (INTERFACES)... 170 FIGURE 38: CLASS DIAGRAM SESSIONSYSTEM (CLASSES)... 172 FIGURE 39: CLASS DIAGRAM SESSIONCONDITION... 175 FIGURE 40: CLASS DIAGRAM DATADICTIONARY (INTERFACES)... 177 FIGURE 41: CLASS DIAGRAM DATADICTIONARY (CLASSES)... 180 FIGURE 42: INTERACTION DIAGRAM - UNCOMMITTED DATA HANDLING... 195 FIGURE 43: INTERACTION DIAGRAM - PHYSICAL STORAGE OF A RECORD... 196 FIGURE 44: INTERACTION DIAGRAM - INSERTION IN INDEX... 197 FIGURE 45: CLASS DIAGRAM FILESYSTEM (INTERFACES)... 199 FIGURE 46: CLASS DIAGRAM FILESYSTEM (CLASSES)... 201 Copyright 2005 Daffodil Software Ltd. 5

FIGURE 47: CLASS DIAGRAM INDEXSYSTEM (INTERFACES)... 205 FIGURE 48: CLASS DIAGRAM INDEXSYSTEM (CLASSES)... 206 FIGURE 49: INTERACTION DIAGRAM - PARSE QUERY... 212 FIGURE 50: INTERACTION DIAGRAM - CLASS GENERATION FOR PARSING RULES... 213 FIGURE 51: CLASS DIAGRAM PARSERSYSTEM... 215 Copyright 2005 Daffodil Software Ltd. 6

Preface Purpose Purpose of Daffodil DB Design Document is to describe the design and the architecture of Daffodil DB. The design is expressed in sufficient detail so as to enable all the developers to understand the underlying architecture of Daffodil DB. Logical architecture of JDBC driver, Server, DML, DDL, DQL, Session, Data Store and Parser of Daffodil DB are explained. Highlights of the documents are: Interaction Diagrams of all the component modules of Daffodil DB are explained. Classes and Interfaces of all the modules have been thoroughly explained. Examples with valid and invalid cases are provided wherever necessary. Note: Daffodil DB Design Document is a beta document. We are working towards making the document more user-friendly. Copyright 2005 Daffodil Software Ltd. 7

Target Audience This Design document is intended to act as a technical reference tool for developers involved in the development of Daffodil DB/One$DB. This document assumes that you have sufficient understanding of the following concepts: RDBMS and its various component modules. SQL Java and JDBC Interaction Diagrams Classes and Interfaces Note: Daffodil DB Design Document is not intended for end-users. Copyright 2005 Daffodil Software Ltd. 8

Pre-requisites Daffodil DB requires Java JRE 1.4 or higher. Since Daffodil DB is written in Java, it can run on any platform that supports the Java runtime environment 1.4 or higher. The compiled files are contained in Java Archives (JARs) and have to be defined in the CLASSPATH environment variable: Copyright 2005 Daffodil Software Ltd. 9

Top Level Interaction Diagrams JDBC Driver Server Parser DDL DML DQL Session Data Store Figure 1: TOP LEVEL INTERACTION DIAGRAM Copyright 2005 Daffodil Software Ltd. 10

execute DDL query User will execute its DDL (Data Definition Language) query through the Daffodil DB JDBC Driver. DDL queries can be used to create, drop or alter objects in the database. Objects allowed are schema, tables, views, triggers, domains, procedures, roles, and constraints. Objects once created will remain persistent in the database. JDBC Server Parser DDL Session DataStore User will give call for executing the DDL query through JDBC driver Server uses parser to parse the query. Parser will check the query 1: execute DDL query 2: parse query 3: create object Server will pass the parsed object to DDL for execution DDL will do the semantic checking of the query and will store the information in the system tables Session will save the information onto the physical storage for persistence 4: execute query 5: Update meta-data info 6: save info in physical storage Figure 2: Interaction Diagram - execute DDL query Flow Explanations: 1: JDBC driver will pass the user query to server for execution. Server will return an object having information about the result of the query. Exceptions: Query is invalid Object already exists. 2 & 3: Server will give the query to parser for parsing. Parser will parse the query and create a tree-type object representing the content of the query. The tree-type object will be Java classes representing different rules of the SQL grammar. Copyright 2005 Daffodil Software Ltd. 11

4: Server will give call to the parsed objects for execution. DDL will perform the semantic checking of the query. After performing the semantic checking of the query, DDL will update the information about the object in the system tables. DDL will also apply the rules specified in SQL 99 specification for the given query. Exceptions: Violation of rule specified in SQL 99 specification. 5: Session will update the meta data information and interact with data store to save the info in the physical storage. 6: Data Store will interact with physical storage to store the meta-data info. Exception: No space on physical storage. Copyright 2005 Daffodil Software Ltd. 12

execute DML query JDBC Driver Server Parser DM Session DataStore User will execute DML query through the JDBC driver. Server uses parser to parse the query. Parser will check the query syntax. 1: execute DML query 2: parse query 3: create object Server will pass the parsed object to DML for execution DML will check the semantic of the query and will retrieve the affected rows from session. DML will pass the new values to session to change the affected rows. DML will apply the constraints and triggers on the affected rows. 4: execute query 5: navigate rows 6: retrieve rows from physical storage 7: Change affected rows 8: apply constraints and triggers Session will save the affected rows onto physical storage. 9: save changes 10: save affected rows to physical storage Figure 3: Interaction Diagram - execute DML query Flow Explanations: 1: JDBC driver will pass the user query to server for execution. Server will return the count of the rows affected by the query. Exceptions: Constraint violation. Execution Trigger in execution Query is invalid. 2 & 3: Server will give the query to parser for parsing. Parser will parse the query and create a tree-type object representing the overall structure of the query. The tree-type object will be Java classes representing different rules of the SQL grammar. 4: Server will pass the parsed object to DML for execution. DML will perform the semantic checking of the query. DML will check the rules specified in SQL specification for the given query. Copyright 2005 Daffodil Software Ltd. 13

Exception Constraint violation 5 & 6: Session will be requested to retrieve all the rows of the given table according to the specified condition. Session will interact with Data System to retrieve rows from the physical storage. 7: Session will check for the locking of the rows being changed by the DML. Exception: Row modified by another user 8: DML will also apply the constraints and triggers created by the user on the given table. 9 & 10: After doing all the operations, DML will save the changes by interacting with the Session. Copyright 2005 Daffodil Software Ltd. 14

execute DQL query JDBC Driver Server Parser DQL Session DataStore User will give call to execute its DQL query through JDBC driver. Server uses parser to parse the query. Parser will check the query syntax. Server will pass the parsed object to DQL for execution. DQL will check semantics of the query and will use session to retrieve the rows satisfying the query. 1: execute DQL query 2: parse query 3: create object 4: execute query Loop for all the tables involved in query. 5: make query execution plan 6: retrieve rows 7: retrieve rows from physical storage 8: adjust retrieved rows according to query DQL returns an iterator object which will be used to iterate the result of the DQL query. 10: iterator object 9: iterator object Figure 4: Interaction Diagram - execute DQL query Flow Explanations: 1: JDBC driver will pass the user query to server for execution. Server will return an iterator object which can be used to iterate the result of the DQL query. Exceptions: Query is invalid. 2 & 3: Server will give the query to parser for parsing. Parser will parse the query and create a tree-type object representing the overall structure of the query. The tree-type object will be java classes representing different rules of the SQL grammar. 4: Server will pass the parsed object to DQL for execution. DQL will perform the semantic checking of the query. DQL will also the query according to the rules of SQL specification. DQL will make an execution plan for the query. Execution plan will have the information about solving query optimally. DQL will interact with the session to retrieve rows according to the transaction isolation level of the user. DQL will create an iterator object. Iterator can be used to iterate the results of the query. Iterator can be navigated in forward and backward direction. Copyright 2005 Daffodil Software Ltd. 15

5: Execution plan will be containing information about how to solve query optimally. DQL will retrieve meta-data info from Session and will use meta-data to find indexes for solving conditions specified in query. 6 & 7: Session will retrieve rows of the specified table according to the transaction isolation level. Session will interact with data system to retrieve rows from physical storage. Session will also check user privileges on the given table and columns. 8: DQL will adjust the retrieved rows according to query. DQL will be adjusting the rows according to join clause, group by clause, order by clause etc. 9 & 10: DQL returns an iterator object which will be used to iterate the result of the DQL query. Copyright 2005 Daffodil Software Ltd. 16

JDBC Driver JDBC Driver responsiblities: Support for JDBC 3.0 API Executable in embedded and network mode JDBC Driver will be the main interface through which a user can interact with Daffodil DB. JDBC driver can be used to execute any type of query on the database. JDBC driver will function according to JDBC 3.0 API specified by Sun MicroSystems. JDBC driver will provide all the information about the database and its objects. JDBC driver will provide access to meta-data as well as data of the tables. JDBC driver will support the execution of all types of queries including DDL, DML, DQL and DCL. Using JDBC driver user will be able to execute SQL statements, retrieve results and perform changes to the database. For more comprehensive and up-to-date information on JDBC and JTA, please refer the following resources: http://java.sun.com/products/jdbc http://java.sun.com/products/jta http://developer.java.sun.com/developer/books/jdbctutorial/ http://java.sun.com/products/jdbc/download.html#corespec30 JDBC driver will be given for Embedded as well as for Network version of Daffodil DB. We will be providing other interfaces like Command-Line tool, GUI-based tool (Graphical User interface) for performing the above mentioned operations. Copyright 2005 Daffodil Software Ltd. 17

Server Overview Server responsibilities: Processing JDBC driver requests Managing currently active users Access to multiple databases concurrently Multi-threaded environment Server will be responsible for processing the JDBC driver requests. Server will provide the environment to the user for the execution of different type of queries. Queries can be DDL, DML, DQL and DCL. Queries can be executed on different databases concurrently. Server will be providing a multi-threaded environment for concurrent execution of queries on the same database. Server can be started in two modes i.e. Embedded and Network. Copyright 2005 Daffodil Software Ltd. 18

ServerSystem Class Diagram: Classes UserImpl Server User ServerImpl DistributedConnectionImpl <<depends>> Connection ConnectionImpl XAResource PreparedSta tement PreparedStatementImpl XAResourceImpl NonParameterizedStatement Figure 5: Class Diagram - ServerSystem Classes: Connection (Interface) Connection represents the interface through which the user interacts with the database server. Connection is responsible for handling transaction and executing SQL queries given by the user. Server (Interface) Server is responsible for providing the connections to the users and ensuring the databases are not used by another instance of database server. Server verifies the user while giving the connection to the database. ServerImpl ( ) ServerImpl provides the implementation of the Server interface. ConnectionImpl ( ) ConnectionImpl provides the implementation of Connection interface. DistributedConnectionImpl ( ) DistributedConnectionImpl provides the implementation of Connection interface in distributed transactions environment. DistributedConnectionImpl delegates its call to underlying Connection instance. Copyright 2005 Daffodil Software Ltd. 19

PreparedStatement (Interface) PreparedStatement is responsible for executing the query with parameters. Users make an instance of PreparedStatement by passing the query to the Connection and then user executes the query by giving the values of the parameters. PreparedStatementImpl ( ) PreparedStatementImpl provides the implementation of the PreparedStatement interface. NonParameterizedStatement ( ) NonParameterizedStatement provides the implementation of PreparedStatement interface in case of queries having no parameters. User (Interface) User is responsible for interacting with the end-user through GUI. User manages the connections and provide functionality for creating/droping the database. UserImpl ( ) UserImpl provides the implementation of the User interface. XAResource (Interface) XAResource represents a distributed resource. XAResourceImpl ( ) XAResourceImpl provides the implementation of XAResource interface. Copyright 2005 Daffodil Software Ltd. 20

DML Overview DML responsibilities: Executing DML queries Applying constraints and triggers Concurrent execution of queries DML will be responsible for executing all types of DML queries specified in SQL 99 specification. DML queries include insert, update and delete. DML will also take care of constraints and triggers. DML is very crucial in the overall performance of the database server. It needs to be optimized for best performance. Multiple users can execute different DML queries on the same table concurrently. DML queries include: Insert Update Delete Applying constraints Executing triggers Constraints: Constraints are used to specify or check the validity of the records inserted/modified. Different constraints are: Unique constraint: Constraint specifies that every combination or value of the specified columns should be unique. Null values are not considered for checking the constraint. In case the constraint is applied on a combination of columns and either of the column is having a null value, constraint is not checked for that record/row. Primary constraint: Primary constraint is similar to unique constraint but it does not allow null value in the columns. In case multiple columns are specified in the constraint then no column can have null value in it. Check constraint: Check constraint specifies a condition that must be satisfied by the column value of each row of the table. Constraint can be applied on single column or multiple columns. For checking the constraint the specified condition is evaluated and if the current value of the column doesn t satisfies the condition, an error is thrown. Foreign constraint: Foreign constraint is also known as referential constraint. Foreign constraint specifies that the value of column(s) refers to a value of column(s) of some row in other table. This constraint is mostly used to refer Details to the Master record. Copyright 2005 Daffodil Software Ltd. 21

In case of null value in the column(s), value is not checked in the other table. Foreign constraint also specifies what to do in case of update/delete of other table row. User can specify the following behaviour: No action, Restrict, Cascade, Set Default and Set Null. Null Constraint: Null constraint is used to restrict the Null value in the column, specified in the constraint. Triggers: Triggers are used to perform specified action on the occurrence of other operations on the table. Triggers can be applied in a variety of ways. Triggers are applied on DML operations performed on the table. There are two types of triggers: Statement-Level Trigger: Statement-level trigger is executed once for each DML statement. Row-Level Trigger: Row-level trigger is executed once for each record affected by the DML statement execution. Trigger can be applied on any of DML query i.e. Insert, Update and Delete. Trigger can be configured to be executed before or after execution of operation. It can be restricted by applying a condition for its execution. In case of Update, a list of columns can also be specified. Triggers have a set of SQL statements which are executed when the trigger is executed. Triggers can be nested i.e. an SQL statement of a trigger can initiate another trigger. DML Query Execution: DML query execution can be divided into four parts, mainly privileges checking, records modification, constraints checking and triggers execution. DML query specifies a single table whose records/rows will be modified. In case of insert query, user specifies the columns and values of the record. In case of update query, user specifies a where condition for records to be modified and expressions for retrieving column values. In case of delete query, user specifies a where condition for records to be deleted. DML query will first of all check the privileges of the user executing the query. Current User must have the privileges for the specified query and columns being affected. DML query will be locating the records to be operated by either solving the where condition or by making the record using the values specified. DML query will perform the specified operation on the records found above. DML query will also perform constraints checking on every record modified. In case there is a violation, DML query will rollback the changes done and will throw an error to the user. DML query will also execute the triggers applied by users on the above operation. As in the case of constraints, if there is any error or violation, DML query will rollback all the changes done and throw an error to user. DML query will always start a sub-transaction under current transaction so that changes done by the current query can be reverted in case of error and on successful execution, changes done under sub-transaction will become part of current transaction. Copyright 2005 Daffodil Software Ltd. 22

Optimization of DML Query: Using Indexes to solve condition: If we have indexes created on the table and there is a condition on the columns of indexes, then we should use the index to solve the condition. Using Indexes for constraints checking: In case of Unique/Primary constraint, we can use the index created on the column of the constraints for checking. If the current value is present in the index, then an error should be thrown. Also in case of foreign constraint, we can use the referenced table index for checking the current value of the column(s). In case the current value is not present in the index, an error should be thrown. More details: Using Indexes: In case of update and delete statement, if a condition is specified then we can use indexes to solve it. If more than one index is available on the columns involved in the condition then the index containing maximum number of condition columns should be selected. We can also consider size of columns for selecting an index. If we have a condition and it can t be solved by a single index, then we should split the condition if the individual parts can be solved by indexes. We can also consider use of multiple indexes to solve the condition. Removing redundant conditions: We can remove redundant conditions involving greater than and less than operator. We can remove the conditions involving AND and OR using the following rules: Predicate OR True --- True Predicate OR False --- Predicate Predicate AND True --- Predicate Predicate AND False --- False We can replace predicate containing null value with Unknown value. Eg a = null, a > null can be replaced with Unknown value. Condition/query rewriting: We can rewrite the conditions to optimize the query execution. o We can use the following law of algebra to rewrite the condition involving NOT operator: NOT (A AND B) = NOT A or NOT B; A and B are predicates. NOT (A OR B) = NOT A and NOT B; A and B are predicates. o We can rewrite the predicate involving NOT and greater than/less than. Copyright 2005 Daffodil Software Ltd. 23

NOT (A > 2) A <= 2 NOT (A < 2) A >= 2 NOT (A >=2) A < 2 NOT (A <=2) A > 2 NOT (A! = 5) A =5 NOT (A = 5) A! = 5 Using Indexes for constraints checking: We will be creating indexes on unique and primary constraint columns to speed up the constraints checking, retrieving and modification. In case of unique and primary constraint, we can use index to check whether the current value of the column is existing in the table. In case of foreign constraint, we can use index of the referenced table to check whether the current value is valid. Triggers Optimization: We can cache the parsed objects of SQL queries specified in the trigger. We can avoid semantic checking of SQL queries because SQL queries are checked semantically during trigger creation. DML RESPONSIBILITIES 1. Insert 2. Update 3. Delete 4. Triggers 5. Constraints 6. Default clause 7. Auto Increment Values 8. Sequences 1. Semantic Checking () a) Check for table existence b) Check the existence of columns of statement in table c) Check for column ambiguity d) Check for cardinality e) Check for degree f) Check the data types of values in query with the data types of column in table g) Check the semantic checking of Sub query, if any. Copyright 2005 Daffodil Software Ltd. 24

Check the existence of table in SQL query Invalid: Insert into Tab1 values (1, A ) Comment: No object called Tab1. Valid: Create Table Tab1 (a int, b char (1)) Insert into Tab1 values (1, A ) Check the existence of columns names of statement in table Invalid: Create Table Tab1 (a int, b char (1)) Insert into Tab1 (a, c) values (1, A ) Insert into Tab1 (T2.a) values (2) Valid: Create Table Tab1 (a int, b char (1)) Insert into Tab1 (a, b) values (1, A ) Check for column ambiguity Invalid: Create Table Tab1 (a int, b char (1)) Insert into Tab1 (a, a) values (1, 2) Valid: Create Table Tab1 (a int, b char (1)) Insert into Tab1 (a) values (2) Check for cardinality (number of columns defined in insert statement should be equal to number of values specified) Invalid: Create Table Tab1 (a int, b char (1)) Insert into Tab1 (a, b) values (1, A, B ) Insert into Tab1 (a) values (1, A ) Insert into Tab1 (a) values (select * from Tab1) Valid: Create Table Tab1 (a int, b char (1)) Insert into Tab1 (a) values (2) Check for degree (number of rows from select query should be equal to one) Invalid: Create Table Tab1 (a int, b char (1)) Insert into Tab1 (a, b) values (1, A ) Insert into Tab1 (a, b) values (2, B ) Insert into Tab1 (a, b) values (select * from Tab1) Valid: Create Table Tab1 (a int, b char (1)) Insert into Tab1 (a, b) values (1, A ) Copyright 2005 Daffodil Software Ltd. 25

Insert into Tab1 (a, b) values (select * from Tab1) Check for data types of values in query with the data types of respective column in table Invalid: Create Table Tab1 (a int, b char (1)) Insert into Tab1 (a) values ( abc ) Valid: Create Table Tab1 (a int, b char (1)) Insert into Tab1 (a) values (1) Execution Insert: 1. Convert the data type of values in insert statement, according to the data type of the columns defined in table. If user has created a table with column of varchar data type and inserting a numeric value without quotes, Daffodil DB will convert the numeric value to varchar type. 2. Add the default value, if user has not provided the values of columns defined with default clause, otherwise record will be inserted with user value. 3. Add auto increment value, if table has a column with auto increment property. If value is provided within the statement by user it takes precedence in respect to the auto generated value. 4. Add the value generated by sequence, if user has used any sequence in statement. 5. Finally insert these values in a table as a row. 6. If any sub query is used in insert statement, Daffodil DB will fetch all the records of the sub query to insert them into table. Update: 1. Convert the data type of values of set clause list in update statement, according to the data type of the columns defined in the table. If user has created a table with column of varchar data type and inserting a numeric value without quotes, Daffodil DB will convert the numeric value to varchar type. 2. Add the value generated by the sequence, if user has used any sequence in statement. 3. Update all the records if user has not specified any where clause. If user has specified it, get the navigator on condition and update all records, which satisfy the condition given in the statement. Copyright 2005 Daffodil Software Ltd. 26

Delete: 1. Delete all records if user has not specified any where clause. If user has specified it, get the navigator on condition and delete all records, which satisfy the condition given in the statement. Examples: a) Insert into Tab2(a, b) values (Default, Default) Default values for columns, b and a, are inserted through this query and rest of the columns are inserted with null values. b) Insert into Tab1 default values Default values in all columns with default clause are inserted through this query and rest of the columns are inserted with null values. c) Insert into Tab1 (b, a) values( ATop,1) Simply inserts records with value ATop and 1 in columns b and a. d) Insert into Tab1 select * from Tab2 This statement will insert all the records of Tab2 table in table Tab1. Number of columns in table Tab1 and Tab2 should be equal. e) Insert into Tab1 (a) values (seq1.next ()), here seq1 is the sequence. This statement will insert a row with values returned by sequence. f) Insert into Tab1 (a) values(1),(2),(3) This statement will insert 3 rows in table Tab1 with values 1, 2, 3 in column a. g) Update Tab1 set a = 5 This statement will update all records of the table with value 5 in column a. h) Update Tab1 set a = 5 where b = A This statement will update all records, which is having the value A in column b, of the table with value 5 in column a. i) Update Tab1 set a = 3, b = T This statement will update all records of the table with value 5 in column a and value T in column b. j) Update Tab1 set a = 10, b = Z where a = 3 This statement will update all records, which is having the value 3 in column a, of the table with value Z in column b and 10 in column a. k) Update Tab1 set a = seq.nextval where a = 3; This statement will update all records, which is having the value 3 in column a, of the table with value generated by sequence. l) Update Tab1 set a = 23 where a = seq.currentval Copyright 2005 Daffodil Software Ltd. 27

This statement will update all records, which is having the value equal to the current value of the sequence in column a, of the table with value 23 in column a. m) Update Tab1 set a = 50 were a in (select id from Tab2 where id >5) This statement will update all records, which is having the value of a is equal to any of the id we got from the select query. n) Delete from Tab1 Deletes all record from table. o) Delete from Tab1 where a = 1 All the record will be deleted which satisfy the condition a = 1 p) Delete from Tab1 where a > 5 All the record will be deleted which satisfy the condition a > 5 Default Clause: The default clause allows one to specify default values for a given column. Possible default values can be any literal / null value / datetime / valuefunction / USER / CURRENT_USER / CURRENT_ROLE / SESSION_USER / CURRENT_PATH / any implicitly typed value specification. Default value clause is set for a column at the time of creation of a table. And its values are provided at the time of insertion. We insert the default value in a row even when the user has not specified the name of default column in insert column list. Default value is overwritten when user has provided value for the column that has default value. For Example: Result: Create table student (Rollno integer, SName varchar (20), memo varchar (200) DEFAULT CURRENT_USER); Insert into student (Rollno, Sname) values (1, Rohan ); Insert into student values (1, Rohan, deepak ); Select * from student; Rollno SName memo 1 Rohan daffodil 1 Rohan deepak Copyright 2005 Daffodil Software Ltd. 28

Auto Increment: To assign incremental value for a column we use auto increment option. There is no need for the user to provide value for the column that has auto increment option because server itself provides incremental value for this column. However, user also can provide value for the column. By default, column value starts from 1 with Increment factor 1. User can declare only following data type field for auto increment option: BIGINT, BYTE, INT, INTEGER, LONG, SMALLINT, TINYINT, DOUBLE PRECISION, FLOAT, REAL, DEC, DECIMAL, NUMERIC For Example: Result: Create table student (Rollno long autoincrement, SName varchar (20)); insert into student values (30, 'rohit'); insert into student (Sname) values ( 'rohit'); insert into student values (48, 'rohit'); insert into student (Sname) values ( 'george'); insert into student values (1, 'first'); insert into student (Sname) values ( 'last'); select * from student; Rollno SName 30 rohit 31 rohit 48 gohit 49 george 1 first 50 last Sequence: Sequences are very similar to auto increment except that auto increment applies on table level and sequence on database level. We can use single sequence in many tables Copyright 2005 Daffodil Software Ltd. 29

For Example: create table users.users.student( roll integer, address varchar(20)); create sequence seq start with 2 increment by 2 minvalue 2 maxvalue 100 cycle; insert into student values ( seq.nextval, '2' ); insert into student values ( seq.nextval, '3' ); insert into student values ( seq.nextval, '4' ); Result: select * from student; roll address 2 2 4 3 6 4 Constraints: Types of Constraints 1. Primary Constraints 2. Unique Constraints 3. Check Constraints 4. Referential Constraints Primary Constraints: We check primary constraints only for insert and update statement. Primary constraints are checked even if user has not provided the column, having primary key, in his statement. For checking of primary constraints, we scan whole table to maintain uniqueness of the column. However, to check this constraint in optimized way, we use index created on primary column. For Example: Create table tab1 (c1 integer primary key, c2 char (10)) Here we created a table with two-column c1 with integer and c2 with char data type. In addition, we have applied a primary key on column c1. Following queries will show you the behaviour of the primary constraint. 1. insert into tab1 values(1, a ) Copyright 2005 Daffodil Software Ltd. 30

This query will be executed successfully and in result of the query one row will be inserted in table with values 1 in column c1 and a in column c2. 2. Insert into tab1 (c2) values ( a ) User on executing this query will face a Primary Key Violation exception. Because he has not mentioned any value for column c1 and null value is not allowed in Primary Constaint. 3. Insert into tab1 (c1,c2) values (2, b ) On executing this query, one row will be inserted in table with values 2 in column c1 and b in column c2. 4. Insert into tab1 (c1,c2) values (1, c ) On executing this query user will face a Primary Key Violation exception because table has already a row with value 1 in column c1. Unique Constraints: Unique constraints are very similar to primary constraint except that unique constraints allow null values in column. To check this constraint, database scan whole table to maintain the uniqueness of the column. Database use index created on columns that are included in unique constraint for optimization purpose. In this constraint database will check the unique constraint only if user has defined the column in statement. For Example: Create table tab1 (c1 integer unique, c2 char (10)) Here we created a table with two-column c1 with integer and c2 with char data type. In Additional, we have applied a unique constraint on column c1. Using following queries we are trying to show you the behaviour of the unique constraint. 1 Insert into tab1 values (1, a ) This query will be executed successfully and in result of the query one row will be inserted in table with values 1 in column c1 and a in column c2. 2 Insert into tab1 (c2) values ( a ) This query will be executed successfully and one row will be inserted in table with value null in column c1 and a in column c2. 3 Insert into tab1 (c1, c2) values (null, b ) This query will be executed successfully and one row will be inserted in table with value null in column c1 and b in column c2. 4 Insert into tab1 (c1, c2) values (1, c ) User on executing this query will face a Unique Constraint Violation exception because table has already a row with value 1 in column c1. Copyright 2005 Daffodil Software Ltd. 31

Check Constraints: To verify check constraint, database solves the condition applied by user on column. For solving condition, database use values from the current row which is being inserted or updated. Check constraints are applicable only on insert and update statement. Daffodil DB does not verify this constraint for delete statement. If any sub query is included in check constraint, then first the database solve the select statement and then verify the given check. Examples: 1. Create table tab1 (c1 integer check (c1 > 5), c2 char(10)) Invalid: Valid: Insert into tab1 values (1, A ) Insert into tab1 values (7, A ) 2. Create table tab1 (c1 integer not null, c2 char(10)) Invalid: Valid: Insert into tab1 values (null, A ) Insert into tab1 values (2l, A ) 3. Create table tab2(c1 integer, c2 integer) Create table tab1 (c1 integer check (c1 >select max(c1)from tab2),c2 char (10)). Insert into tab2 values (2, 5) Insert into tab2 values (5, 10) Invalid: Insert into tab1 values (1, a ) This query will throw check constraint violation exception because sub query will return value 5 as maximum value and value assigned in this statement is less than that. Valid: Insert into tab1 values (50, a ) This query will execute successfully because sub query will return value 5 as maximum value and value assigned in this statement is greater than that which satisfy the check constraint. Copyright 2005 Daffodil Software Ltd. 32

Referential Constraints: Referencing constraints are checked for insert and update statement. For checking the referencing constraints, database will scan the referenced table completely according the specified match type. As we know referenced table column, to which referencing column refers, is always a primary or unique column and for primary and unique constraint columns we create indexes. Therefore, we use these indexes for the optimization purpose. Types of Match: Simple Full Partial Criteria for matching rows for referencing constraints: Simple match type Insertion and modification in referencing table is allowed only if the referencing column has null value in any column or all non-null values should match to the corresponding referenced columns value of any row. Full match type Every referencing column value of a row should have null values in all referencing column or all referencing columns value should be equal to the corresponding referenced column value of any row. Partial match type Confirm Referencing columns of a row must have a non-null value and this non-null value should be equal to the corresponding referenced column value of any row. Example: Scenario 1: Create table country (Cname varchar (20), Cid Integer, Population Integer, Primary key (Cname, Cid, Population) Create table state (Sname varchar(20),cname varchar(20),cid Integer,Population Integer,Foreign key(cname,cid,population) References country(cname,cid,population) match full) Insert into country ( India, 91, 200000) Copyright 2005 Daffodil Software Ltd. 33

Invalid: Valid: Insert into state ( Delhi, null, null, 200000) Insert into state ( Delhi, India, 1, 200000) Insert into state ( Delhi, India, 1, null) Insert into state ( De, India, 91, 200000) Insert into state ( Delhi, null, null, null) Scenario 2: Create table country (Cname varchar(20),cid Integer,Population Integer, Primary key(cname,cid,population) Create table state (Sname varchar(20),cname varchar(20),cid Integer,Population Integer,Foreign key(cname,cid,population) References country(cname,cid,population) match partial) Insert into country ( India, 91, 200) Invalid: Valid: Scenario 3: Insert into state ( Delhi, null, null, null) Insert into state ( Delhi, India, 1, null) Insert into state ( Delhi, India, null, 200) Insert into state ( De, India, null, null) Insert into state ( Delhi, null, 91, null) Create table country (Cname varchar(20),cid Integer,Population Integer, Primary key(cname,cid,population) Create table state (Sname varchar(20),cname varchar(20),cid Integer,Population Integer,Foreign key(cname,cid,population) References country(cname,cid,population) match simple) Insert into country values ( India, 91, 200) Invalid: Valid: Insert into state values ( Delhi, India, 1,200) Insert into state values ( Delhi, India, 91, 91) Insert into state values ( Delhi, Aus, 91, 200) Insert into state values ( De, India, null, null) Insert into state values ( Delhi, India, 91, 200) Copyright 2005 Daffodil Software Ltd. 34

How to modify referenced table: Referenced constraints are checked for update and delete statement. Whenever user modifies the record in referenced table, we follow the rule, action and match type specified on that constraint to perform operations on Referencing table. We have two types of rules i.update Rule ii.delete Rule Both rules have the following actions: Cascade Restrict Set null Set default No Action In some of the following topics, you will find terms like matching rows and unique matching rows. Here is a brief description of these terms: Matching Rows: If Simple Match or Full Match is specified, then for a given row in the referenced table, every row in the referencing table such that the referencing column values equal the corresponding referenced column values in referenced table for the referential constraint is a matching row. If Partial Match is specified, then for a given row in the referenced table, every row in the referencing table has, at least one non-null referencing column value and the non-null referencing column value equals the corresponding referenced column values for the referential constraint is a matching row. Unique Matching Rows: If Partial Match is specified, then for a given row in the referenced table, every matching row for that given row, that is a matching row only to the given row in the referenced table for the referential constraint is a unique matching row. For a given row in the referenced table, a matching row for that given row that is not a unique matching row for that given row for the referential constraints is a unique matching row. Case: a) If Simple or Full Match is specified, then i. If delete rule specifies cascade, then every matching row from referencing table corresponding to the referenced table will be deleted. Copyright 2005 Daffodil Software Ltd. 35

ii. iii. iv. If delete rule specifies set null, then every matching row from referencing table corresponding to the referenced table will be set as null value. If delete rule specifies set default, then for every referencing table, in every unique matching row in referencing table, each referencing column in referencing table is set to the default value. If delete rule specifies restrict and there are some matching rows, then an exception will be raised, Integrity constraint violation restrict violation v. If delete rule specified no action, then no action will be performed on referencing table. vi. vii. viii. ix. If update rule specifies cascade, for every referencing table, in every matching row in referencing table is updated to the new value of that referenced column. If update rule specifies set null, for every referencing table, in every matching row in referencing table, each referencing column in referencing table that corresponds with a referenced column is set to the null value. If update rule specifies set default, for every referencing table, in every matching row in referencing table, the referencing column in referencing table that corresponds with a referenced column is set to the default value. If update rule specifies restrict and there are some matching rows in referencing table, then an exception will be raised, Integrity constraint violation restrict violation Case: b) If Partial Match is specified i. If delete rule specifies cascade, then every unique row from referencing table corresponding to the referenced table will be deleted. ii. iii. iv. If delete rule specifies set null, then every unique matching row from referencing table corresponding to the referenced table will be set to null. If delete rule specifies set default, then for every referencing table, in every unique matching row in referencing table, each referencing column is set to the default value. If delete rule specifies restrict and there are some unique matching rows, then an exception will be raised, Integrity constraint violation restrict violation v. If delete rule specifies no action, then no action will be performed on the referencing table. Copyright 2005 Daffodil Software Ltd. 36

vi. vii. viii. ix. If update rule specifies cascade, for every referencing table, for each unique matching row in referencing table that contains a non-null value in the referencing column C1 in referencing table that corresponds with the updated referenced column C2, C1 is updated to the new value of C2. If update rule specifies set null, than in every unique matching row in referencing table that contains a non-null value in a referencing column in referencing table that corresponds with the updated column, that referencing column is set to the null value. If update rule specifies set default, for every referencing table, in every unique matching row in referencing table that contains a non-null value in a referencing column in referencing table that corresponds with the updated column, that referencing column is set to the default value. If update rule specifies restrict and there are some unique matching rows, then an exception will be raised, Integrity constraint violation restrict violation Examples: i. Simple delete cascade: Create table country (Cname varchar(10), Cid Integer, Population Integer, PRIMARY KEY (Cname, Cid ) ) Create table state ( Sname varchar(10), Sid Integer PRIMARY KEY, Cname varchar (10), Cid Integer, FOREIGN KEY(Cname,Cid) REFERENCES country(cname,cid)match SIMPLE ON DELETE CASCADE ) "; Records in country table: Insert into country values ( India1, 1, 100) Insert into country values ( India2, 2, 100) Insert into country values ( India4, 4, 100) Insert into country values ( India5, 5, 100) Records in state table: Insert into state values ( s1, 1, India1, 1) Insert into state values ( s2, 2, India2, 2) Insert into state values ( s4, 4, India4, 4) Insert into state values ( s1, 1, India2, null) Insert into state values ( s1, 1, null, 12) Copyright 2005 Daffodil Software Ltd. 37

Case: 1. On deleting record from country table with condition cname = India4, only one row from state table will be deleted which have sname as s4. 2. On deleting record from country table with condition cname= India2, one row from state table will be deleted that have sname as s2. 3. On deleting record from country table with condition cname= India5, state table will remain same because there is no matching row. ii. Simple delete set null: Create table country (Cname varchar(10), Cid Integer, Population Integer, PRIMARY KEY (Cname, Cid ) ) Create table state( Sname varchar(10), Sid Integer PRIMARY KEY, Cname varchar(10), Cid Integer, FOREIGN KEY(Cname,Cid) REFERENCES country( Cname,Cid ) MATCH SIMPLE ON DELETE set null ) "; Records in country table: Insert into country values ( India1, 1, 100) Insert into country values ( India2, 2, 100) Insert into country values ( India4, 4, 100) Insert into country values ( India5, 5, 100) Records in state table: Insert into state values ( s1, 1, India1, 1) Insert into state values ( s2, 2, India2, 2) Insert into state values ( s4, 4, India4, 4) Insert into state values ( s1, 1, India2, null) Insert into state values ( s1, 1, null, 12) Case: 1. On deleting record from country table with condition cname = India4, only one row from state table will be updated with null values in columns cname and cid that have sname as s4 2. On deleting record from country table with condition cname= India2, one row from state table will be updated with null values in columns cname and cid that have sname as s2. 3. On deleting record from country table with condition cname= India5, state table will remain same because there is no matching row. Copyright 2005 Daffodil Software Ltd. 38

iii. Simple delete set default: Create table country (Cname varchar(10), Cid Integer, Population Integer, PRIMARY KEY (Cname, Cid ) ) Create table state( Sname varchar(10), Sid Integer PRIMARY KEY, Cname varchar(10) default India1, Cid Integer default 1, FOREIGN KEY(Cname,Cid) REFERENCES country( Cname,Cid ) MATCH SIMPLE ON DELETE set default ) "; Records in country table: Insert into country values ( India1, 1, 100) Insert into country values ( India2, 2, 100) Insert into country values ( India4, 4, 100) Insert into country values ( India5, 5, 100) Records in state table: Insert into state values ( s1, 1, India1, 1) Insert into state values ( s2, 2, India2, 2) Insert into state values ( s4, 4, India4, 4) Insert into state values ( s1, 1, India2, null) Insert into state values ( s1, 1, null, 12) Case: 1. On deleting record from country table with condition cname = India4, only one row from state table will be updated with India1 and 1 in columns cname and cid that have sname as s4 2. On deleting record from country table with condition cname= India2, one row from state table will be updated with India1 and 1 in columns cname and cid that have sname as s2. 3. On deleting record from country table with condition cname= India5, state table will remain same because there is no matching row. iv. Simple delete Restrict: Create table country (Cname varchar(10), Cid Integer, Population Integer, PRIMARY KEY (Cname, Cid ) ) Create table state( Sname varchar(10), Sid Integer PRIMARY KEY, Cname varchar(10), Cid Integer, FOREIGN KEY(Cname,Cid) REFERENCES country( Cname,Cid ) MATCH SIMPLE ON DELETE restrict) "; Records in country table: Insert into country values ( India1, 1, 100) Insert into country values ( India2, 2, 100) Copyright 2005 Daffodil Software Ltd. 39