+ All Categories
Home > Documents > Daffodil DB Design-document

Daffodil DB Design-document

Date post: 30-May-2018
Category:
Upload: pankaj27484
View: 217 times
Download: 0 times
Share this document with a friend

of 221

Transcript
  • 8/14/2019 Daffodil DB Design-document

    1/221

    Daffodil DB

    Design Document (Beta)

    Version 4.0

    January 2005

  • 8/14/2019 Daffodil DB Design-document

    2/221

    Copyright Daffodil Software LimitedSco 42,3rd FloorOld Judicial Complex, Civil lines

    Gurgaon - 122001Haryana, 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 productnames are trademarks of their respective companies.

    Copyright 2005 Daffodil Software Ltd. 2

    http://www.daffodildb.com/http://www.daffodildb.com/
  • 8/14/2019 Daffodil DB Design-document

    3/221

    Table of Contents

    TABLE OF FIGURES...................................................................................................... 5

    PREFACE.......................................................................................................................... 7

    PURPOSE....................................................................................................................................... 7TARGET AUDIENCE ...................................................................................................................... 8PRE-REQUISITES........................................................................................................................... 9

    TOP LEVEL INTERACTION DIAGRAMS............................................................... 10

    EXECUTE DDL QUERY ............................................................................................................... 11EXECUTE DML QUERY............................................................................................................... 13EXECUTE DQL QUERY ............................................................................................................... 15

    JDBC DRIVER ............................................................................................................... 17

    SERVER .......................................................................................................................... 18

    OVERVIEW ................................................................................................................................. 18SERVERSYSTEM ......................................................................................................................... 19

    DML ................................................................................................................................. 21

    OVERVIEW ................................................................................................................................. 21CONSTRAINTSYSTEM ................................................................................................................. 75TRIGGERSYSTEM ....................................................................................................................... 79SQL............................................................................................................................................ 82

    DDL .................................................................................................................................. 85

    OVERVIEW ................................................................................................................................. 85

    SQL............................................................................................................................................ 95DESCRIPTORS ........................................................................................................................... 101

    DQL................................................................................................................................ 105

    OVERVIEW ............................................................................................................................... 105SQL.......................................................................................................................................... 146NAVIGATOR ............................................................................................................................. 149EXECUTIONPLAN ..................................................................................................................... 153

    SESSION........................................................................................................................ 156

    OVERVIEW ............................................................................................................................... 156SESSIONSYSTEM ...................................................................................................................... 170

    DATADICTIONARY................................................................................................................... 177

    DATA STORE............................................................................................................... 182

    OVERVIEW ............................................................................................................................... 182FILESYSTEM............................................................................................................................. 199INDEXSYSTEM.......................................................................................................................... 205

    PARSER......................................................................................................................... 210

    Copyright 2005 Daffodil Software Ltd. 3

  • 8/14/2019 Daffodil DB Design-document

    4/221

    OVERVIEW ............................................................................................................................... 210PARSER SYSTEM ...................................................................................................................... 215

    RELATED DOCUMENTATION ............................................................................... 218

    SIGN UP FOR SUPPORT ........................................................................................... 219

    WE NEED FEEDBACK! ............................................................................................. 220

    LICENSE NOTICE ...................................................................................................... 221

    Copyright 2005 Daffodil Software Ltd. 4

  • 8/14/2019 Daffodil DB Design-document

    5/221

    Table of Figures

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

    Copyright 2005 Daffodil Software Ltd. 5

  • 8/14/2019 Daffodil DB Design-document

    6/221

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

    Copyright 2005 Daffodil Software Ltd. 6

  • 8/14/2019 Daffodil DB Design-document

    7/221

    Preface

    Purpose

    Purpose of Daffodil DB Design Document is to describe the design and the architectureof Daffodil DB. The design is expressed in sufficient detail so as to enable all thedevelopers to understand the underlying architecture of Daffodil DB. Logical architectureof JDBC driver, Server, DML, DDL, DQL, Session, Data Store and Parser of Daffodil DBare explained.

    Highlights of the documents are:

    Interaction Diagrams of all the component modules of Daffodil DB areexplained.

    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 towardsmaking the document more user-friendly.

    Copyright 2005 Daffodil Software Ltd. 7

  • 8/14/2019 Daffodil DB Design-document

    8/221

    Target Audience

    This Design document is intended to act as a technical reference tool for developersinvolved in the development of Daffodil DB/One$DB.

    This document assumes that you have sufficient understanding of the followingconcepts:

    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

  • 8/14/2019 Daffodil DB Design-document

    9/221

    Pre-requisites

    Daffodil DB requires Java JRE 1.4 or higher. Since Daffodil DB is written in Java, it canrun 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 theCLASSPATH environment variable:

    Copyright 2005 Daffodil Software Ltd. 9

  • 8/14/2019 Daffodil DB Design-document

    10/221

    Top Level Interaction Diagrams

    JDBC Driver

    Server

    DMLDDL DQL

    Session

    Data Store

    Parser

    Figure 1: TOP LEVEL INTERACTION DIAGRAM

    Copyright 2005 Daffodil Software Ltd. 10

  • 8/14/2019 Daffodil DB Design-document

    11/221

    execute DDL query

    User will execute its DDL (Data Definition Language) query through the Daffodil DBJDBC 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, andconstraints. Objects once created will remain persistent in the database.

    JDBC Server Parser DDL DataStoreSession

    1: execute DDL query

    2: parse query

    4: execute query

    5: Update meta-data info

    6: save info in physical storage

    3: create object

    User will give call forexecuting the DDL querythrough JDBC driver

    Server uses parser toparse the query. Parserwill check the query

    Server will pass theparsed object to DDL forexecution

    DDL will do the semanticchecking of the query andwill store the informationin the system tables

    Session will save theinformation onto thephysical storage forpersistence

    Figure 2: Interaction Diagram - execute DDL query

    low Explanations:

    pass the user query to server for execution. Server will return an

    is invalid

    xists.

    2 & 3: Server will give the query to parser for parsing. Parser will parse the query and

    F

    1: JDBC driver willobject having information about the result of the query.

    Exceptions:

    Query

    Object already e

    create a tree-type object representing the content of the query. The tree-type object willbe Java classes representing different rules of the SQL grammar.

    Copyright 2005 Daffodil Software Ltd. 11

  • 8/14/2019 Daffodil DB Design-document

    12/221

    4: Server will give call to the parsed objects for execution. DDL will perform the

    ion of rule specified in SQL 99 specification.

    5: Se teract with data store to save

    ysical storage to store the meta-data info.

    pace on physical storage.

    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 alsoapply the rules specified in SQL 99 specification for the given query.

    Exceptions:

    Violat

    ssion will update the meta data information and inthe info in the physical storage.

    6: Data Store will interact with ph

    Exception:

    No s

    Copyright 2005 Daffodil Software Ltd. 12

  • 8/14/2019 Daffodil DB Design-document

    13/221

    execute DML query

    JDBC Driver Server Parser DM

    1: execute DML query

    2: parse query

    4: execute query

    Session

    7: Change affected rows

    DataStore

    6: retrieve rows fromphysical storage

    5: navigate rows

    3: create object

    8: applyconstraints andtriggers

    9: save changes10: save affected rows tophysical storage

    User will execute DML querythrough the JDBC driver.

    Server uses parser to parsethe query. Parser will check thequery syntax.

    Server will pass the parsedobject to DML for execution

    DML will check the semantic ofthe query and will retrieve theaffected rows from session.

    DML will pass the new valuesto session to change theaffected rows.

    DML will apply the constraintsand triggers on the affectedrows.

    Session will save the affectedrows onto 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 thecount 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 andcreate a tree-type object representing the overall structure of the query. The tree-typeobject 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 thesemantic checking of the query. DML will check the rules specified in SQL specificationfor the given query.

    Copyright 2005 Daffodil Software Ltd. 13

  • 8/14/2019 Daffodil DB Design-document

    14/221

    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 thephysical 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 giventable.

    9 & 10: After doing all the operations, DML will save the changes by interacting with theSession.

    Copyright 2005 Daffodil Software Ltd. 14

  • 8/14/2019 Daffodil DB Design-document

    15/221

    execute DQL query

    JDBC Driver Server Parser DQL

    1: execute DQL query

    2: parse query

    4: execute query

    Session DataStore

    6: retrieve rows

    7: retrieve rows from physical storage

    8: adjust retrieved rows according to query

    3: create object

    9: iterator object

    10: iterator object

    5: make query execution plan

    Loop for all the

    tables involvedin query.

    User will give call to executeits DQL query through JDBCdriver.

    Server uses parser to parsethe query. Parser will checkthe query syntax.

    Server will pass the parsedobject to DQL for execution.

    DQL will check semantics ofthe query and will use

    session to retrieve the rowssatisfying the query.

    DQL returns an iteratorobject which will be used toiterate the result of the DQLquery.

    Figure 4: Interaction Diagram - execute DQL query

    Flow Explanations:

    1: JDBC driver will pass the user query to server for execution. Server will return aniterator 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 andcreate 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 SQLspecification. DQL will make an execution plan for the query. Execution plan will havethe information about solving query optimally. DQL will interact with the session toretrieve rows according to the transaction isolation level of the user. DQL will create aniterator object. Iterator can be used to iterate the results of the query. Iterator can benavigated in forward and backward direction.

    Copyright 2005 Daffodil Software Ltd. 15

  • 8/14/2019 Daffodil DB Design-document

    16/221

    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 forsolving 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 physicalstorage. 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 rowsaccording to join clause, group byclause, order byclause etc.

    9 & 10: DQL returns an iterator object which will be used to iterate the result of theDQL query.

    Copyright 2005 Daffodil Software Ltd. 16

  • 8/14/2019 Daffodil DB Design-document

    17/221

    JDBC Driver

    JDBC Driver responsiblities:Support for JDBC 3.0 API

    Executable in embedded and network modeJDBC Driver will be the main interface through which a user can interact with DaffodilDB. JDBC driver can be used to execute any type of query on the database. JDBCdriver will function according to JDBC 3.0 API specified by Sun MicroSystems. JDBCdriver will provide all the information about the database and its objects. JDBC driver willprovide access to meta-data as well as data of the tables. JDBC driver will support theexecution of all types of queries including DDL, DML, DQL and DCL. Using JDBC driveruser will be able to execute SQL statements, retrieve results and perform changes to thedatabase.

    For more comprehensive and up-to-date information on JDBC and JTA, please refer thefollowing 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 (GraphicalUser interface) for performing the above mentioned operations.

    Copyright 2005 Daffodil Software Ltd. 17

    http://java.sun.com/products/jdbchttp://java.sun.com/products/jtahttp://developer.java.sun.com/developer/Books/JDBCTutorial/http://corespec30/http://corespec30/http://developer.java.sun.com/developer/Books/JDBCTutorial/http://java.sun.com/products/jtahttp://java.sun.com/products/jdbc
  • 8/14/2019 Daffodil DB Design-document

    18/221

    Server

    Overview

    Server responsibilities:

    Processing JDBC driver requestsManaging currently active usersAccess to multiple databases concurrentlyMulti-threaded environment

    Server will be responsible for processing the JDBC driver requests. Server will providethe environment to the user for the execution of different type of queries. Queries can beDDL, DML, DQL and DCL. Queries can be executed on different databasesconcurrently. Server will be providing a multi-threaded environment for concurrentexecution of queries on the same database.

    Server can be started in two modes i.e. Embedded and Network.

    Copyright 2005 Daffodil Software Ltd. 18

  • 8/14/2019 Daffodil DB Design-document

    19/221

    ServerSystem

    Class Diagram: Classes

    Connection

    Server

    ServerImpl

    ConnectionImpl

    DistributedConnectionImpl

    PreparedStatement

    PreparedStatementImpl

    NonParameterizedStatement

    User

    UserImpl

    XAResource

    XAResourceImpl

    Figure 5: Class Diagram - ServerSystem

    Classes:

    Connection (Interface)Connection represents the interface through which the user interacts with the databaseserver. Connection is responsible for handling transaction and executing SQL queriesgiven by the user.

    Server (Interface)Server is responsible for providing the connections to the users and ensuring thedatabases are not used by another instance of database server. Server verifies the userwhile 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 indistributed transactions environment. DistributedConnectionImpl delegates its call tounderlying Connection instance.

    Copyright 2005 Daffodil Software Ltd. 19

  • 8/14/2019 Daffodil DB Design-document

    20/221

    PreparedStatement (Interface)PreparedStatement is responsible for executing the query with parameters. Users makean instance of PreparedStatement by passing the query to the Connection and then userexecutes the query by giving the values of the parameters.

    PreparedStatementImpl ( )PreparedStatementImpl provides the implementation of the PreparedStatementinterface.

    NonParameterizedStatement ( )NonParameterizedStatement provides the implementation of PreparedStatementinterface in case of queries having no parameters.

    User (Interface)User is responsible for interacting with the end-user through GUI. User manages theconnections 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

  • 8/14/2019 Daffodil DB Design-document

    21/221

  • 8/14/2019 Daffodil DB Design-document

    22/221

  • 8/14/2019 Daffodil DB Design-document

    23/221

    Optimization of DML Query:

    Using Indexes to solve condition:If we have indexes created on the table and there is a condition on the columnsof 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 thecolumn 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 thereferenced table index for checking the current value of the column(s). In casethe 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 thenthe 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 cant 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 followingrules:

    Predicate OR True --- TruePredicate OR False --- PredicatePredicate AND True --- PredicatePredicate 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

  • 8/14/2019 Daffodil DB Design-document

    24/221

    NOT (A > 2) A = 2NOT (A >=2) A < 2NOT (A 2NOT (A! = 5) A =5NOT (A = 5) A! = 5

    Using Indexes for constraints checking:

    We will be creating indexes on unique and primary constraint columns to speed up theconstraints checking, retrieving and modification.

    In case of unique and primary constraint, we can use index to check whether thecurrent value of the column is existing in the table.

    In case of foreign constraint, we can use index of the referenced table to checkwhether the current value is valid.

    Triggers Optimization:

    We can cache the parsed objects of SQL queries specified in the trigger. We canavoid semantic checking of SQL queries because SQL queries are checkedsemantically during trigger creation.

    DML RESPONSIBILITIES

    1. Insert2. Update3. Delete4. Triggers

    5. Constraints6. Default clause7. Auto Increment Values8. Sequences

    1. Semantic Checking ()

    a) Check for table existenceb) Check the existence of columns of statement in tablec) Check for column ambiguityd) Check for cardinality

    e) Check for degreef) Check the data types of values in query with the data types of column in tableg) Check the semantic checking of Sub query, if any.

    Copyright 2005 Daffodil Software Ltd. 24

  • 8/14/2019 Daffodil DB Design-document

    25/221

    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

  • 8/14/2019 Daffodil DB Design-document

    26/221

    Insert into Tab1 (a, b) values (select * from Tab1)

    Check for data types of values in query with the data types of respective columnin 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 ofthe columns defined in table. If user has created a table with column of varchardata type and inserting a numeric value without quotes, Daffodil DB will convertthe numeric value to varchar type.

    2. Add the default value, if user has not provided the values of columns defined withdefault clause, otherwise record will be inserted with user value.

    3. Add auto incrementvalue, if table has a column with auto increment property. Ifvalue is provided within the statement by user it takes precedence in respect tothe auto generated value.

    4. Add the value generated by sequence, if user has used any sequence instatement.

    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 recordsof the sub query to insert them into table.

    Update:

    1. Convert the data type of values of set clause list in update statement, accordingto the data type of the columns defined in the table. If user has created a tablewith 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 hasspecified it, get the navigator on condition and update all records, which satisfythe condition given in the statement.

    Copyright 2005 Daffodil Software Ltd. 26

  • 8/14/2019 Daffodil DB Design-document

    27/221

    Delete:

    1. Delete all records if user has not specified any where clause. If user hasspecified it, get the navigator on condition and delete all records, which satisfythe 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 ofthe columns are inserted with null values.

    b) Insert into Tab1 default valuesDefault values in all columns with default clause are inserted through this queryand 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 Tab2This statement will insert all the records of Tab2 table in table Tab1. Number ofcolumns 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 = AThis statement will update all records, which is having the value A in columnb, of the table with value 5 in column a.

    i) Update Tab1 set a = 3 , b = TThis statement will update all records of the table with value 5 in column a andvalue T in column b.

    j) Update Tab1 set a = 10 , b = Z where a = 3This 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

  • 8/14/2019 Daffodil DB Design-document

    28/221

    This statement will update all records, which is having the value equal to thecurrent value of the sequence in column a, of the table with value 23 in columna.

    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 Tab1Deletes all record from table.

    o) Delete from Tab1 where a = 1All the record will be deleted which satisfy the condition a = 1

    p) Delete from Tab1 where a > 5All 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. Possibledefault values can be any literal / null value / datetime / valuefunction / USER /CURRENT_USER / CURRENT_ROLE / SESSION_USER / CURRENT_PATH / anyimplicitly typed value specification.

    Default value clause is set for a column at the time of creation of a table. And its valuesare provided at the time of insertion. We insert the default value in a row even when theuser has not specified the name of default column in insert column list. Default value isoverwritten when user has provided value for the column that has default value.

    For Example:

    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;

    Result:

    Rollno SName memo

    1 Rohan daffodil

    1 Rohan deepak

    Copyright 2005 Daffodil Software Ltd. 28

  • 8/14/2019 Daffodil DB Design-document

    29/221

    Auto Increment:

    To assign incremental value for a column we use auto increment option. There is noneed for the user to provide value for the column that has auto increment optionbecause server itself provides incremental value for this column. However, user also canprovide 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:

    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;

    Result:

    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 ontable level and sequence on database level. We can use single sequence in manytables

    Copyright 2005 Daffodil Software Ltd. 29

  • 8/14/2019 Daffodil DB Design-document

    30/221

    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' );

    select * from student;

    Result:

    roll address

    2 2

    4 3

    6 4

    Constraints:

    Types of Constraints

    1. Primary Constraints2. Unique Constraints3. Check Constraints

    4. Referential Constraints

    Primary Constraints:

    We check primary constraints only for insert and update statement. Primary constraintsare checked even if user has not provided the column, having primary key, in hisstatement. For checking of primary constraints, we scan whole table to maintainuniqueness of the column. However, to check this constraint in optimized way, we useindex 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. Inaddition, we have applied a primary key on column c1. Following queries will show youthe behaviour of the primary constraint.

    1. insert into tab1 values(1, a)

    Copyright 2005 Daffodil Software Ltd. 30

  • 8/14/2019 Daffodil DB Design-document

    31/221

    This query will be executed successfully and in result of the query onerow will be inserted in table with values 1 in column c1 and a incolumn 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 c1and 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 2in 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 Violationexception 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 constraintsallow null values in column. To check this constraint, database scan whole table tomaintain the uniqueness of the column. Database use index created on columns that areincluded in unique constraint for optimization purpose. In this constraint database willcheck 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 querieswe 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 onerow will be inserted in table with values 1 in column c1 and a incolumn c2.

    2 Insert into tab1 (c2) values (a)This query will be executed successfully and one row will be insertedin 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 insertedin 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 Violationexception because table has already a row with value 1 in column c1.

    Copyright 2005 Daffodil Software Ltd. 31

  • 8/14/2019 Daffodil DB Design-document

    32/221

    Check Constraints:

    To verify check constraint, database solves the condition applied by user on column. Forsolving condition, database use values from the current row which is being inserted orupdated. Check constraints are applicable only on insert and update statement. DaffodilDB 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 thegiven check.

    Examples:

    1. Create table tab1 (c1 integer check (c1 > 5), c2 char(10))

    Invalid:Insert into tab1 values (1,A)

    Valid:Insert into tab1 values (7,A)

    2. Create table tab1 (c1 integer not null, c2 char(10))

    Invalid:Insert into tab1 values (null, A)

    Valid: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 subquery will return value 5 as maximum value and value assigned in thisstatement is less than that.

    Valid:Insert into tab1 values (50, a)

    This query will execute successfully because sub query will returnvalue 5 as maximum value and value assigned in this statement isgreater than that which satisfy the check constraint.

    Copyright 2005 Daffodil Software Ltd. 32

  • 8/14/2019 Daffodil DB Design-document

    33/221

    Referential Constraints:

    Referencing constraints are checked for insert and update statement. For checking thereferencing constraints, database will scan the referenced table completely accordingthe specified match type. As we know referenced table column, to which referencingcolumn refers, is always a primary or unique column and for primary and unique

    constraint columns we create indexes. Therefore, we use these indexes for theoptimization 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 columnhas null value in any column or all non-null values should match to the correspondingreferenced columns value of any row.

    Full match type

    Every referencing column value of a row should have null values in all referencingcolumn or all referencing columns value should be equal to the correspondingreferenced column value of any row.

    Partial match type

    Confirm Referencing columns of a row must have a non-null value and this non-nullvalue 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),CidInteger,Population Integer,Foreign key(Cname,Cid,Population) Referencescountry(Cname,Cid,Population) match full)

    Insert into country (India, 91, 200000)

    Copyright 2005 Daffodil Software Ltd. 33

  • 8/14/2019 Daffodil DB Design-document

    34/221

    Invalid:Insert into state (Delhi, null, null, 200000)Insert into state (Delhi, India, 1, 200000)Insert into state (Delhi, India, 1, null)

    Valid: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, Primarykey(Cname,Cid,Population)

    Create table state (Sname varchar(20),Cname varchar(20),CidInteger,Population Integer,Foreign key(Cname,Cid,Population) Referencescountry(Cname,Cid,Population) match partial)

    Insert into country (India, 91, 200)

    Invalid:Insert into state (Delhi, null, null, null)Insert into state (Delhi, India, 1, null)Insert into state (Delhi, India, null, 200)

    Valid:Insert into state (De, India, null, null)Insert into state (Delhi, null, 91, null)

    Scenario 3:Create table country (Cname varchar(20),Cid Integer,Population Integer,

    Primary key(Cname,Cid,Population)

    Create table state (Sname varchar(20),Cname varchar(20),CidInteger,Population Integer,Foreign key(Cname,Cid,Population)References country(Cname,Cid,Population) match simple)

    Insert into country values (India, 91, 200)

    Invalid:Insert into state values (Delhi, India, 1,200)Insert into state values (Delhi, India, 91, 91)

    Insert into state values (Delhi, Aus, 91, 200)Valid:Insert into state values (De, India, null, null)Insert into state values (Delhi, India, 91, 200)

    Copyright 2005 Daffodil Software Ltd. 34

  • 8/14/2019 Daffodil DB Design-document

    35/221

    How to modify referenced table:

    Referenced constraints are checked for update and delete statement. Whenever usermodifies the record in referenced table, we follow the rule, action and match typespecified on that constraint to perform operations on Referencing table.

    We have two types of rules

    i.Update Ruleii.Delete Rule

    Both rules have the following actions:

    CascadeRestrictSet nullSet defaultNo Action

    In some of the following topics, you will find terms like matching rows and uniquematching 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 thecorresponding referenced column values in referenced table for the referential constraintis 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-nullreferencing column value equals the corresponding referenced column values for thereferential constraint is a matching row.

    Unique Matching Rows:

    If Partial Match is specified, then for a given row in the referenced table, every matchingrow for that given row, that is a matching row only to the given row in the referencedtable for the referential constraint is a unique matching row. For a given row in thereferenced table, a matching row for that given row that is not a unique matching row forthat given row for the referential constraints is a unique matching row.

    a) If Simple or Full Match is specified, then

    Case:

    i. If delete rule specifies cascade, then every matching row from referencingtable corresponding to the referenced table will be deleted.

    Copyright 2005 Daffodil Software Ltd. 35

  • 8/14/2019 Daffodil DB Design-document

    36/221

    ii. If delete rule specifies set null, then every matching row from referencingtable corresponding to the referenced table will be set as null value.

    iii. If delete rule specifies set default, then for every referencing table, in everyunique matching row in referencing table, each referencing column inreferencing table is set to the default value.

    iv. If delete rule specifies restrict and there are some matching rows, then anexception will be raised, Integrity constraint violation restrict violation

    v. If delete rule specified no action, then no action will be performed onreferencing table.

    vi. If update rule specifies cascade, for every referencing table, in everymatching row in referencing table is updated to the new value of thatreferenced column.

    vii. If update rule specifies set null, for every referencing table, in every matching

    row in referencing table, each referencing column in referencing table thatcorresponds with a referenced column is set to the null value.

    viii. If update rule specifies set default, for every referencing table, in everymatching row in referencing table, the referencing column in referencing tablethat corresponds with a referenced column is set to the default value.

    ix. If update rule specifies restrict and there are some matching rows inreferencing table, then an exception will be raised, Integrity constraintviolation restrict violation

    b) If Partial Match is specified

    Case:

    i. If delete rule specifies cascade, then every unique row from referencing tablecorresponding to the referenced table will be deleted.

    ii. If delete rule specifies set null, then every unique matching row fromreferencing table corresponding to the referenced table will be set to null.

    iii. If delete rule specifies set default, then for every referencing table, in everyunique matching row in referencing table, each referencing column is set to

    the default value.

    iv. If delete rule specifies restrict and there are some unique matching rows,then an exception will be raised, Integrity constraint violation restrictviolation

    v. If delete rule specifies no action, then no action will be performed on thereferencing table.

    Copyright 2005 Daffodil Software Ltd. 36

  • 8/14/2019 Daffodil DB Design-document

    37/221

    vi. If update rule specifies cascade, for every referencing table, for each uniquematching row in referencing table that contains a non-null value in thereferencing column C1 in referencing table that corresponds with the updatedreferenced column C2, C1 is updated to the new value of C2.

    vii. 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 inreferencing table that corresponds with the updated column, that referencingcolumn is set to the null value.

    viii. If update rule specifies set default, for every referencing table, in everyunique matching row in referencing table that contains a non-null value in areferencing column in referencing table that corresponds with the updatedcolumn, that referencing column is set to the default value.

    ix. If update rule specifies restrict and there are some unique matching rows,then an exception will be raised, Integrity constraint violation restrictviolation

    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 DELETECASCADE ) ";

    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

  • 8/14/2019 Daffodil DB Design-document

    38/221

    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, statetable 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 , Cnamevarchar(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 onerow from state table will be updated with null values in columns cname and cidthat have sname as s4

    2. On deleting record from country table with condition cname=India2, one rowfrom 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, statetable will remain same because there is no matching row.

    Copyright 2005 Daffodil Software Ltd. 38

  • 8/14/2019 Daffodil DB Design-document

    39/221

    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 onerow from state table will be updated with India1 and 1 in columns cname and cidthat have sname as s4

    2. On deleting record from country table with condition cname=India2, one rowfrom state table will be updated with India1 and 1 in columns cname and cid thathave sname as s2.

    3. On deleting record from country table with condition cname=India5, statetable 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 , Cnamevarchar(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

  • 8/14/2019 Daffodil DB Design-document

    40/221

    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, anexception will be raised, Integrity constraint violation restrict violation becausein state table a matching row exists.

    2. On deleting record from country table with condition cname=India2, an

    exception will be raised, Integrity constraint violation restrict violation becausein state table a matching row exists.

    3. On deleting record from country table with condition cname=India5, recordfrom country table will be deleted and state table will remain same because thereis no matching row.

    v. Simple delete no action:

    Create table country (Cname varchar(10), Cid Integer, Population Integer,PRIMARY KEY (Cname, Cid ) )

    Create table state( Sname varchar(10) , Sid Integer PRIMARY KEY , Cnamevarchar(10), Cid Integer, FOREIGN KEY(Cname,Cid) REFERENCES country(Cname,Cid ) MATCH SIMPLE ON DELETE no action) ";

    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. 40

  • 8/14/2019 Daffodil DB Design-document

    41/221

    Case:

    1. On deleting record from country table with condition cname = India4, theparticular record will be deleted from country table without affecting state table.

    2. On deleting record from country table with condition cname=India2, the

    particular record will be deleted from country table without affecting state table.

    3. On deleting record from country table with condition cname=India5, theparticular record will be deleted from country table without affecting state table.

    vi. Full 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 , Cnamevarchar(10) , Cid Integer , FOREIGN KEY(Cname,Cid) REFERENCES country(

    Cname,Cid ) MATCH FULL 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, India1, 1)Insert into state values (s1, 5, India1, 1)

    Case:

    1. On deleting record from country table with condition cname = India4, onlyone row from state table will be deleted which have sname as s4.

    2. On deleting record from country table with condition cname=India2, one rowfrom state table will be deleted that have sname as s2.

    3. On deleting record from country table with condition cname=India5, statetable will remain same because there is no matching row.

    Copyright 2005 Daffodil Software Ltd. 41

  • 8/14/2019 Daffodil DB Design-document

    42/221

    vii. Full 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 FULL 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, India1, 1)Insert into state values (s1, 1, India1, 1)

    Case:

    1. On deleting record from country table with condition cname = India4, onlyone row from state table will be updated with null values in columns cname andcid that have sname as s4

    2. On deleting record from country table with condition cname=India2, one rowfrom state table will be updated with null values in columns cname and cid thathave sname as s2.

    3. On deleting record from country table with condition cname=India5, statetable will remain same because there is no matching row.

    viii. Full delete set default:

    Create table country (Cname varchar(10), Cid Integer, Population Integer,PRIMARY KEY (Cname, Cid ) )

    Create table state(Sname varchar(10),Sid Int PRIMARY KEY,Cnamevarchar(10)defaultIndia1,Cid Int default 1,FOREIGNKEY(Cname,Cid)REFERENCES Country(Cname,Cid) MATCH FULL ONDELETE set default ) ";

    Records in country table:

    Insert into country values (India1, 1, 100)Insert into country values (India2, 2, 100)

    Copyright 2005 Daffodil Software Ltd. 42

  • 8/14/2019 Daffodil DB Design-document

    43/221

    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, India1, 1)Insert into state values (s1, 5, India1, 1)

    Case:

    1. On deleting record from country table with condition cname = India4, only onerow from state table will be updated with India1 and 1 in columns cname and cidthat 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 thathave sname as s2.

    3. On deleting record from country table with condition cname=India5, statetable will remain same because there is no matching row.

    ix. Full 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 FULL ON DELETE restrict) ";

    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, 5, India1, 1)Insert into state values (s1, 6, India1, 1)

    Copyright 2005 Daffodil Software Ltd. 43

  • 8/14/2019 Daffodil DB Design-document

    44/221

    Case:

    1. On deleting record from country table with condition cname = India4, anexception will be raised, Integrity constraint violation restrict violation becausein state table a matching row exists.

    2. On deleting record from country table with condition cname=India2, anexception will be raised, Integrity constraint violation restrict violation becausein state table a matching row exists.

    3. On deleting record from country table with condition cname=India5, recordfrom country table will be deleted and state table will remain same because thereis no matching row.

    x. Full delete No Action:

    Create table country (Cname varchar(10), Cid Integer, Population Integer,PRIMARY KEY (Cname, Cid ) )

    Create table state( Sname varchar(10) , Sid Integer PRIMARY KEY , Cnamevarchar(10), Cid Integer, FOREIGN KEY(Cname,Cid) REFERENCES country(Cname,Cid ) MATCH FULL ON DELETE no action) ";

    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, 5, India1, 1)Insert into state values (s1, 6, India1, 1)

    Case:

    1. On deleting record from country table with condition cname = India4, theparticular record will be deleted from country table without affecting state table.

    2. On deleting record from country table with condition cname=India2, theparticular record will be deleted from country table without affecting state table.

    3. On deleting record from country table with condition cname=India5, theparticular record will be deleted from country table without affecting state table.

    Copyright 2005 Daffodil Software Ltd. 44

  • 8/14/2019 Daffodil DB Design-document

    45/221

    xi. Simple update cascade:

    Create table country (Cname varchar(10) , Cid Integer , Population Integer,PRIMARY KEY (Cname, Cid ))

    Create table state( Sname varchar(10),Sid Int PRIMARY KEY,Cnamevarchar(10),Cid Int,FOREIGN KEY(Cname,Cid) REFERENCES country(Cname,Cid )MATCH SIMPLE ON UPDATE 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)

    Case:

    1. On updating a record on country table with condition cname = India4 withvalue India7, only one row from state table will be updated with value India7 incolumn cname, which has sname as s4.

    2. On updating a record on country table with condition cname =India2 withvalue India8, only one row from state table will be updated with value India8 incolumn cname, which has sname as s2.

    3. On updation a record on country table with condition cname=India5, statetable will remain same because there is no matching row.

    xii. Simple update 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 , Cnamevarchar(10) , Cid Integer , FOREIGN KEY(Cname,Cid) REFERENCES country(Cname,Cid ) MATCH SIMPLE ON UPDATE set null ) ";

    Records in country table:

    Insert into country values (India1, 1, 100)Insert into country values (India2, 2, 100)

    Copyright 2005 Daffodil Software Ltd. 45

  • 8/14/2019 Daffodil DB Design-document

    46/221

    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 updating record on country table with condition cname = India4 with valueIndia7, only one row from state table will be updated with null values in columnscname and cid that have sname as s4

    2. On updating record on country table with condition cname =India2 with value

    India8, one row from state table will be updated with null values in columncname and cid that have sname as s2.

    3. On updating record on country table with condition cname=India5 with valueIndia10, state table will remain same because there is no matching row.

    xiii. Simple update 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 UPDATE 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)

    Copyright 2005 Daffodil Software Ltd. 46

  • 8/14/2019 Daffodil DB Design-document

    47/221

    Case:

    1. On updating record on country table with condition cname = India4 withvalue India7, only one row from state table will be updated with India1 and 1 incolumns cname and cid that have sname as s4

    2. On updating record on country table with condition cname =India2 withvalue India8, one row from state table will be updated with India1 and 1 incolumns cname and cid that have sname as s2.

    3. On updating record on country table with condition cname =India5, statetable will remain same because there is no matching row.

    xiv. Simple update 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 , Cnamevarchar(10), Cid Integer, FOREIGN KEY(Cname,Cid) REFERENCES country(Cname,Cid ) MATCH SIMPLE ON UPDATE restrict) ";

    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 updating record on country table with condition cname = India4, anexception will be raised, Integrity constraint violation restrict violation because

    in state table a matching row exists.

    2. On updating record on country table with condition cname=India2, anexception will be raised, Integrity constraint violation restrict violation becausein state table a matching row exists.

    3. On updating record on country table with condition cname=India5, recordfrom country table will be updated and state table will remain same becausethere is no matching row.

    Copyright 2005 Daffodil Software Ltd. 47

  • 8/14/2019 Daffodil DB Design-document

    48/221

    xv. Simple update no action:

    Create table country (Cname varchar(10), Cid Integer, Population Integer,PRIMARY KEY (Cname,Cid))

    Create table state( Sname varchar(10) , Sid Integer PRIMARY KEY , Cnamevarchar(10), Cid Integer, FOREIGN KEY(Cname,Cid) REFERENCES country(Cname,Cid ) MATCH SIMPLE ON UPDATE no action) ";

    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 updating record on country table with condition cname = India4, recordwill be updated from country table without affecting state table.

    2. On updating record on country table with condition cname ==India2, recordwill be updated from country table without affecting state table.

    3. On updating record on country table with condition cname = =India5, recordwill be updated from country table without affecting state table.

    xvi. Full update cascade:

    Create table country(Cname varchar(10),Cid int, Population Integer, PRIMARYKEY (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 Full ON UPDATE 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)

    Copyright 2005 Daffodil Software Ltd. 48

  • 8/14/2019 Daffodil DB Design-document

    49/221

    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, 5, India1, 1)Insert into state values (s1, 6, India1, 1)

    Case:

    1. On udating a record on country table with condition cname = India4 withvalue India7, only one row from state table will be updated with value India7 incolumn cname, which have sname as s4.

    2. On updating a record on country table with condition cname =India2 withvalue India8, only one row from state table will be updated with value India8 incolumn cname, which have sname as s2.

    3. On updation a record on country table with condition cname=India5, statetable will remain same because there is no matching row.

    xvii. Full update set null:

    Create table country (Cname varchar(10),Cid Int , Population Integer, PRIMARYKEY (Cname, Cid ) )

    Create table state( Sname varchar(10),Sid Int PRIMARY KEY,Cnamevarchar(10),Cid Int,FOREIGN KEY(Cname,Cid) REFERENCES country(Cname,Cid ) MATCH FULL ON UPDATE 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, 5, India1, 1)Insert into state values (s1, 6, India1, 1)

    Case:

    1. On updating record on country table with condition cname = India4 withvalue India7, only one row from state table will be updated with null values incolumn cname and cid that have sname as s4

    Copyright 2005 Daffodil Software Ltd. 49

  • 8/14/2019 Daffodil DB Design-document

    50/221

    2. On updating record on country table with condition cname =India2 withvalue India8, one row from state table will be updated with null values in columncname and cid that have sname as s2.

    3. On updating record on country table with condition cname=India5 with value

    India10, state table will remain same because there is no matching row.

    xviii. Full update set default:

    Create table country (Cname varchar(10), Cid Integer, Population Integer,PRIMARY KEY (Cname, Cid ) )

    Create table state(Sname varchar(10),Sid Int PRIMARY KEY , Cnamevarchar(10) default India1, Cid Integer default 1, FOREIGN KEY(Cname,Cid)REFERENCES country( Cname,Cid ) MATCH FULL ON UPDATE 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, 5, India1, 1)

    Insert into state values (s1, 6, India1, 1)

    Case:

    1. On updating record on country table with condition cname = India4 withvalue India7, only one row from state table will be updated with India1 and 1 incolumns cname and cid that have sname as s4.

    2. On updating record on country table with condition cname =India2 withvalue India8, one row from state table will be updated with India1 and 1 incolumns cname and cid that have sname as s2.

    3. On updating record on country table with condition cname =India5, statetable will remain same because there is no matching row.

    xix. Full update restrict:

    Create table country (Cname varchar(10), Cid Integer, Population Integer,PRIMARY KEY (Cname, Cid ) )

    Copyright 2005 Daffodil Software Ltd. 50

  • 8/14/2019 Daffodil DB Design-document

    51/221

    Create table state( Sname varchar(10) , Sid Integer PRIMARY KEY , Cnamevarchar(10), Cid Integer, FOREIGN KEY(Cname,Cid) REFERENCES country(Cname,Cid ) MATCH FULL ON UPDATE restrict) ";

    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, 5, India1, 1)Insert into state values (s1, 6, India1, 1)

    Case:

    1. On updating record on country table with condition cname = India4, anexception will be raised, Integrity constraint violation restrict violation becausein state table a matching row exists.

    2. On updating record on country table with condition cname=India2, anexception will be raised, Integrity constraint violation restrict violation becausein state table a matching row exists.

    3. On updating record on country table with condition cname=India5, record

    from country table will be updated and state table will remain same becausethere is no matching row.

    xx.Full update no action:

    Create table country (Cname varchar(10), Cid Integer, Population Integer,PRIMARY KEY (Cname, Cid ) )

    Create table state( Sname varchar(10) , Sid Integer PRIMARY KEY , Cnamevarchar(10), Cid Integer, FOREIGN KEY(Cname,Cid) REFERENCES country(Cname,Cid ) MATCH FULL ON UPDATE no action) ";

    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:

    Copyright 2005 Daffodil Software Ltd. 51

  • 8/14/2019 Daffodil DB Design-document

    52/221

    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, 5, India1, 1)Insert into state values (s1, 6, India1, 1)

    Case:

    1. On updating record on country table with condition cname = India4, theparticular record will be updated from country table without affecting state table.

    2. On updating record on country table with condition cname = India2, theparticular record will be updated from country table without affecting state table.

    3. On updating record on country table with condition cname = India5, theparticular record will be updated from country table without affecting state table.

    xxi. Partial 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 , Cnamevarchar(10),Cid Integer , FOREIGN KEY(Cname,Cid) REFERENCES country(Cname,Cid ) MATCH PARTIAL 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, 100)Insert into state values (s2, 2, India2, 2)Insert into state values (s4, 4, India4, 4)Insert into state values (s6, 1, India1, null)Insert into state values (s7, 1, null, 100)

    Case:

    1. On deleting record from country table with condition cname = India1, onlyone row from state table will be deleted which have sname as s1 because this isthe only unique matching row for table country.

    2. On deleting record from country table with condition cname=India2, one rowfrom state table will be deleted that have sname as s2.

    Copyright 2005 Daffodil Software Ltd. 52

  • 8/14/2019 Daffodil DB Design-document

    53/221

    3. On deleting record from country table with condition cname=India5, statetable will remain same because there is no matching row.

    xxii. Partial 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 , Cnamevarchar(10) , Cid Integer , FOREIGN KEY(Cname,Cid) REFERENCEScountry(Cname,Cid ) MATCH PARTIAL 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, 100)Insert into state values (s2, 2, India2, 2)Insert into state values (s4, 4, India4, 4)Insert into state values (s6, 1, India1, null)Insert into state values (s7, 1, null, 100)

    Case:

    1. On deleting record from country table with condition cname = India1, only

    one row from state table will be updated with null values in columns cname andcid that have sname as s1 because this is the only unique matching row fortable country.

    2. On deleting record from country table with condition cname=India2, one rowfrom state table will be updated with null values in columns cname and cid thathave sname as s2.

    3. On deleting record from country table with condition cname=India5, statetable will remain same because there is no matching row.

    xxiii.Partial 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 , Cnamevarchar(10) default India4, Cid Integer default 4, FOREIGN KEY(Cname,Cid)REFERENCES country( Cname,Cid ) MATCH PARTIAL ON DELETE set default) ";

    Copyright 2005 Daffodil Software Ltd. 53

  • 8/14/2019 Daffodil DB Design-document

    54/221

    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, 100)Insert into state values (s2, 2, India2, 2)Insert into state values (s4, 4, India4, 4)Insert into state values (s6, 1, India1, null)Insert into state values (s7, 1, null, 100)

    Case:

    1. On deleting record from country table with condition cname = India1, only

    one row from state table will be updated with the values India4 and 4 in columnscname and cid that have sname as s1.

    2. On deleting record from country table with condition cname=India2, one rowfrom state table will be updated with the value India4 and 4 in columns cnameand cid that have sname as s2.

    3. On deleting record from country table with condition cname=India5, statetable will remain same because there is no matching row.

    xxiv. Partial 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 , Cnamevarchar(10), Cid Integer, FOREIGN KEY(Cname,Cid) REFERENCES country(Cname,Cid ) MATCH PARTIAL ON DELETE restrict) ";

    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, 100)Insert into state values (s2, 2, India2, 2)Insert into state values (s4, 4, India4, 4)Insert into state values (s6, 1, India1, null)Insert into state values (s7, 1, null, 100)

    Copyright 2005 Daffodil Software Ltd. 54

  • 8/14/2019 Daffodil DB Design-document

    55/221

    Case:

    1. On deleting record from country table with condition cname = India1, anexception will be raised, Integrity constraint violation restrict violation becausein state table a matching row exists.

    2. On deleting record from country table with condition cname=India2, anexception will be raised, Integrity constraint violation restrict violation becausein state table a matching row exists.

    3. On deleting record from country table with condition cname=India5, theparticular record from country table will be deleted and state table will remainsame because there is no matching row.

    xxv. Partial delete no action:

    Create table country (Cname varchar(10), Cid Integer, Population Integer,PRIMARY KEY (Cname, Cid ) )

    Create table state( Sname varchar(10) , Sid Integer PRIMARY KEY , Cnamevarchar(10), Cid Integer, FOREIGN KEY(Cname,Cid) REFERENCES country(Cname,Cid ) MATCH PARTIAL ON DELETE no action) ";

    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, 100)Insert into state values (s2, 2, India2, 2)Insert into state values (s4, 4, India4, 4)Insert into state values (s6, 1, India1, null)Insert into state values (s7, 1, null, 100)

    Case:

    1. On deleting record from country table with condition cname = India1, theparticular record will be deleted from country table without affecting state table.

    2. On deleting record from country table with condition cname=India2, theparticular record will be deleted from country table without affecting state table.

    3. On deleting record from country table with condition cname=India5, theparticular record will be deleted from country table without affecting state table.

    Copyright 2005 Daffodil Software Ltd. 55

  • 8/14/2019 Daffodil DB Design-document

    56/221

    xxvi. Partial update 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 ,


Recommended