Foreign and Primary Keys in RDM Embedded SQL: Efficiently Implemented Using the Network Model

Similar documents
Database Migration from MySQL to RDM Server


1. INTRODUCTION TO RDBMS

High Availability Using Raima Database Manager Server

2. Basic Relational Data Model

Introduction to Databases

DBMS Questions. 3.) For which two constraints are indexes created when the constraint is added?

æ A collection of interrelated and persistent data èusually referred to as the database èdbèè.

TIM 50 - Business Information Systems

DATABASE MANAGEMENT SYSTEM

1 File Processing Systems

Chapter 1: Introduction. Database Management System (DBMS) University Database Example

How To Create A Table In Sql (Ahem)

5.5 Copyright 2011 Pearson Education, Inc. publishing as Prentice Hall. Figure 5-2

Foundations of Business Intelligence: Databases and Information Management

Instant SQL Programming

Chapter 1: Introduction

Conventional Files versus the Database. Files versus Database. Pros and Cons of Conventional Files. Pros and Cons of Databases. Fields (continued)

Database Design and Normalization

Database Management. Technology Briefing. Modern organizations are said to be drowning in data but starving for information p.

Files. Files. Files. Files. Files. File Organisation. What s it all about? What s in a file?

Data Modeling Basics

ATTACHMENT 6 SQL Server 2012 Programming Standards

SQL Server. 1. What is RDBMS?

Oracle 10g PL/SQL Training

Oracle Database 10g: Introduction to SQL

Oracle Database: SQL and PL/SQL Fundamentals NEW

5. CHANGING STRUCTURE AND DATA

Overview. Physical Database Design. Modern Database Management McFadden/Hoffer Chapter 7. Database Management Systems Ramakrishnan Chapter 16

Oracle Database: SQL and PL/SQL Fundamentals

Oracle Database 10g Express

Intro to Embedded SQL Programming for ILE RPG Developers

CSE 530A Database Management Systems. Introduction. Washington University Fall 2013

Information Systems SQL. Nikolaj Popov

Physical Database Design Process. Physical Database Design Process. Major Inputs to Physical Database. Components of Physical Database Design

1.264 Lecture 15. SQL transactions, security, indexes

Alexander Nikov. 5. Database Systems and Managing Data Resources. Learning Objectives. RR Donnelley Tries to Master Its Data

Week 1 Part 1: An Introduction to Database Systems. Databases and DBMSs. Why Use a DBMS? Why Study Databases??

SQL DATA DEFINITION: KEY CONSTRAINTS. CS121: Introduction to Relational Database Systems Fall 2015 Lecture 7

Maintaining Stored Procedures in Database Application

Planning and Creating a Custom Database

Chapter 13 File and Database Systems

Chapter 13 File and Database Systems

Chapter 6 8/12/2015. Foundations of Business Intelligence: Databases and Information Management. Problem:

- Eliminating redundant data - Ensuring data dependencies makes sense. ie:- data is stored logically

Chapter 2 Database System Concepts and Architecture

Tutorial on Relational Database Design

Triggers & Packages. {INSERT [OR] UPDATE [OR] DELETE}: This specifies the DML operation.

Oracle Database: SQL and PL/SQL Fundamentals

Database System Concepts

Database Programming with PL/SQL: Learning Objectives

ORACLE 9I / 10G / 11G / PL/SQL COURSE CONTENT

Chapter 1: Introduction. Database Management System (DBMS)

Chapter 6. Foundations of Business Intelligence: Databases and Information Management

Elena Baralis, Silvia Chiusano Politecnico di Torino. Pag. 1. Active database systems. Triggers. Triggers. Active database systems.

Introduction to Computing. Lectured by: Dr. Pham Tran Vu

Database Query 1: SQL Basics

IBM Tivoli Software. Document Version 8. Maximo Asset Management Version 7.5 Releases. QBR (Ad Hoc) Reporting and Report Object Structures

BCA. Database Management System

Chapter 6: Physical Database Design and Performance. Database Development Process. Physical Design Process. Physical Database Design

CA IDMS. Database Design Guide. Release , 2nd Edition

COMPONENTS in a database environment

Network Model APPENDIXD. D.1 Basic Concepts

Database Design. Marta Jakubowska-Sobczak IT/ADC based on slides prepared by Paula Figueiredo, IT/DB

Relational model. Relational model - practice. Relational Database Definitions 9/27/11. Relational model. Relational Database: Terminology

A basic create statement for a simple student table would look like the following.

D61830GC30. MySQL for Developers. Summary. Introduction. Prerequisites. At Course completion After completing this course, students will be able to:

Chapter 2. Data Model. Database Systems: Design, Implementation, and Management, Sixth Edition, Rob and Coronel

CA IDMS SQL. Programming Guide. Release

Chapter 9, More SQL: Assertions, Views, and Programming Techniques

Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification


Oracle EXAM - 1Z Oracle Database 11g Release 2: SQL Tuning. Buy Full Product.

Databases and Information Management

Using SQL in RPG Programs: An Introduction

1Z0-117 Oracle Database 11g Release 2: SQL Tuning. Oracle

Trusted RUBIX TM. Version 6. Multilevel Security in Trusted RUBIX White Paper. Revision 2 RELATIONAL DATABASE MANAGEMENT SYSTEM TEL

Overview of Data Management

Demystified CONTENTS Acknowledgments xvii Introduction xix CHAPTER 1 Database Fundamentals CHAPTER 2 Exploring Relational Database Components

Using SAS as a Relational Database

Access Tutorial 2 Building a Database and Defining Table Relationships

Study Notes for DB Design and Management Exam 1 (Chapters 1-2-3) record A collection of related (logically connected) fields.

Raima Database Manager Version 14.0 In-memory Database Engine

In This Lecture. SQL Data Definition SQL SQL. Notes. Non-Procedural Programming. Database Systems Lecture 5 Natasha Alechina

AVOIDANCE OF CYCLICAL REFERENCE OF FOREIGN KEYS IN DATA MODELING USING THE ENTITY-RELATIONSHIP MODEL

1.264 Lecture 11. SQL: Basics, SELECT. Please start SQL Server before each class

Duration Vendor Audience 5 Days Oracle End Users, Developers, Technical Consultants and Support Staff

SQL Server Table Design - Best Practices

What is a database? COSC 304 Introduction to Database Systems. Database Introduction. Example Problem. Databases in the Real-World

ECS 165A: Introduction to Database Systems

Information Systems Analysis and Design CSC John Mylopoulos Database Design Information Systems Analysis and Design CSC340

Performance Management of SQL Server

The Relational Model. Ramakrishnan&Gehrke, Chapter 3 CS4320 1

ANDROID APPS DEVELOPMENT FOR MOBILE GAME

The Relational Model. Why Study the Relational Model?

Darshan Institute of Engineering & Technology PL_SQL

Objectives of SQL. Terminology for Relational Model. Introduction to SQL

Chapter 1: Introduction

DbSchema Tutorial with Introduction in SQL Databases

Transcription:

Foreign and Primary Keys in RDM Embedded SQL: Efficiently Implemented Using the Network Model By Randy Merilatt, Chief Architect - January 2012 This article is relative to the following versions of RDM: RDM Embedded 10.1 Network model databases have been viewed as strictly non-relational and outdated. But in the 1990s when the SQL standard incorporated support for declared foreign keys to represent inter-table relationships, the gap between the relational and the network model representation of a database narrowed. This was exploited by Raima in RDM Server (RDMs) with the introduction of the create join statement that allowed an SQL foreign and primary key relationship to be explicitly mapped into a network model set. in 2009, when Raima decided to add SQL to RDM Embedded (RDMe) we decided to keep RDMe SQL as simple and as free of as many unnecessary, non-standard extensions as possible. Hence, network model sets are automatically (i.e., implicitly) used in the implementation of foreign and primary key relationships. This paper describes how network model sets are implemented in the RDMe core-level database engine, the syntax and semantics of SQL foreign and primary keys, and why the use of network model sets provides an efficient and high performance implementation for them. The Network Database Model: A Little History The primary data organization mechanism that was provided in some very early database management systems (DBMS) was the ability to declare a one-to-many relationship between a parent record type (table) and a child record type. These systems were known as hierarchical model systems because the data was strictly hierarchically arranged each child could have only one parent. The DBMS provided access methods where each child instance for a particular parent record instance could easily and quickly be accessed. Later database systems relaxed the strict hierarchical scheme so that a child could belong to more than one parent and were called network model systems. A standard database language came to be defined by a standards body known as CODASYL ("Conference of Data Systems Languages") that specified how a network model database could be defined (through a DDL Data Definition Language specification) and accessed and manipulated (through a DML Data Manipulation Language specification) designed to work with COBOL programs. The one-to-many parent-child inter-record type relationships in a network model database were specified by what is called a set. The example below shows the DDL for a CODASYL DBMS (Univac DMS 1100 circa 1973) which defines two record types, author and book, and a set that defines the one-to-many relationship between the two. Currently called DMS 2200 which Unisys continues to maintain and support. P a g e 1

Figure 1. Example of a CODASYL DDL Specification of a Parent and Child Record and a Set: RECORD NAME IS AUTHOR RECORD CODE IS 1 LOCATION MODE IS CALC NAMEHASH USING NAME DUPLICATES ARE NOT ALLOWED 02 NAME PIC X(35) 02 YEAR-OF-BIRTH PIC 9999 02 YEAR-OF-DEATH PIC 9999 RECORD NAME IS BOOK RECORD CODE IS 2 LOCATION MODE IS VIA BOOKS-BY-AUTHOR SET 02 TITLE PIC X(60) 02 YEAR-PUBLISHED PIC 9999 SET BOOKS-BY-AUTHOR MODE IS CHAIN LINKED PRIOR ORDER IS LAST OWNER IS AUTHOR MEMBER IS BOOK AUTOMATIC LINKED TO OWNER SET OCCURRENCE SELECTION IS THRU LOCATION MODE OF OWNER Retrieving data is done in a COBOL DML program by navigating through sets to locate the desired records. For example, first a FETCH for a specific AUTHOR record occurrence would be executed followed by a FETCH of each BOOK record that is a member of the BOOKS-BY-AUTHOR set for which the fetched AUTHOR was the owner. Thus, multiple statements are executed in order to retrieve the desired data. In the example above, the BOOK occurrences that are all members of the same set are directly related together through a doubly linked list no index is needed providing optimal (i.e., maximum of 1 logical read) access. The following diagram shows how a typical BOOKS-BY-AUTHOR set instance may be stored in the database. Figure 2. Example Set Instance Implementation: P a g e 2

The DBMS maintains in the owner record pointers to the first and last member records in the linked list and for each member pointers to the prior and next member along with a pointer to the owner. These "pointers" are called database keys (or database addresses) and directly map into the actual location where the record is permanently stored on disk. When a new book is stored along with its title (and whatever other data fields are included in the record's DDL declaration) the author name will also be provided. However, it is not actually stored with the book record but will be used to find the author record with that name so that when the book is stored it will be connected to the correct BOOKS-BY-AUTHOR set instance. In this way the author name functions like the primary key in the AUTHOR record type and a foreign key in the BOOK record type even though no such data field is declared in BOOK. RDMe Core-Level DDL Set Declarations From its original incarnation in 1983 as db_vista, RDM Embedded has been a network model DBMS but one that was designed for use with the C programming language rather than COBOL. Figure 3 below gives the RDMe Core (i.e. lowlevel) DDL specification corresponding to that given in Figure 1. Figure 3. RDMe Core DDL Specification of Parent and Child Record and a Set: record author { unique key char name[36]; short year_of_birth; short year_of_death; } record book { char title[61]; short year_published; } set books_by_author { order last; owner author; member book; } Data retrieval is performed by the C program by making calls to the RDMe Core-level C API functions that lookup records based on a specified key value (e.g., the author name) and then locating the related book records by calling a function that retrieves the members of the set. So, like CODASYL. retrieval is navigational. Declared Foreign and Primary Keys in SQL One-to-many relationships between tables (= record types) in SQL are explicitly defined in the create table statement through primary and foreign key column declarations. A primary key is a column (or columns) in a (parent) table which is used to uniquely identify each row (= record occurrence) of the table. A foreign key is a column (or columns) in a (child) table that is used to identify the primary key value of the related row from the parent table. Foreign key column(s) must be declared to have the identical data type as its referenced primary key column(s). The SQL DDL that corresponds to the DDL given earlier in and Figure 3 is shown in Figure 4 below. P a g e 3

Figure 4. SQL DDL for Parent and Child Tables: create table author ( name year_of_birth year_of_death ); create table book ( title ); char(35) primary key, smallint, smallint char(60), year_published smallint, name char(35) not null references author(name) on delete cascade on update cascade The foreign key is declared on the name column in the book table with the references clause. The on delete cascade and on update cascade clauses specify what is to happen when a row of the author table is deleted or updated. When cascade is specified then on a delete all of the related book rows will automatically be deleted as well. On an update of the author's primary key column (e.g., fixing a misspelled author name) all of the related book rows will automatically updated. In a standard relational DBMS, in order for these operations to be performed in a reasonable amount of time the name column in the book table would need to be indexed (something that the DBMS might automatically create based on the cascade specification). Explicit declaration of foreign keys allows the DBMS to enforce referential integrity in which the system ensures that all rows from the primary key table that are referenced by foreign keys always exist. For example, besides the cascade option, the on clause can specify restrict which means that the update or delete on the author row is not allowed when a book row that references it exists. Retrieval is performed through an SQL select statement that specifies a join between the two tables that conditionally equates the two tables through the foreign and primary keys. The diagram below shows how the rows from the two tables are related through the common foreign and primary key column values. Figure 5. Relational Database Representation of a Parent-Child Table Join: P a g e 4

The dotted-line arrows represent the primary key row being referenced by the foreign key column values they are not actually pointers. The select statement that can be used to retrieve the data is shown below along with its result set. Figure 6. SELECT Statement to Retrieve Author-Book Data: SELECT name, title FROM author natural join book where author.name = "" name title The Time Machine The Island of Dr. Moreau The Invisible Man The War of the Worlds Foreign Key Implementation with Sets An SQL DBMS needs to be able to efficiently manage all of the properties associated with foreign key declarations such as: 1. fast access from the primary key row to all rows with matching foreign key values, 2. fast access from the foreign key row to the referenced primary key row, 3. ability to quickly check to ensure a referenced primary key row exists, 4. ability to quickly determine if a primary key row has references Relational database systems usually do this by creating a unique index on the primary key column values and a nonunique index on the foreign key column values. By having indexes on both the primary and foreign keys all four of the above requirements can be supported. The cost, however, comes in the amount of redundant data introduced by the duplicate foreign key column values in which not only is each stored in a row of the foreign key table but also in the index. Moreover, the cost of accessing a foreign key row using the index, while usually acceptable, may still involve 2 or 3 additional disk accesses. Foreign and primary key relationships can easily and efficiently be implemented using network model sets and that is exactly what RDM Embedded SQL does. By using sets, all of the rows of the foreign key table that reference the same primary key row are maintained in a link list much as is shown in Figure 2. This means that the related rows can be retrieved by direct access (guaranteed to require no more than a single disk read). Use of sets to implement the foreign and primary key relationships also means that the foreign key columns can be virtual that is, their values do not actually need to be stored in the foreign key table as those values can be easily retrieved from the referenced row through the set's owner pointer. That, coupled with the fact that the foreign keys do not need to be indexed, can significantly reduce the amount of redundant data. It also means that the work needed to be done in order to process a cascade update (where the foreign keys are all instantly updated whenever the primary key value changes) and delete (the related rows to be deleted are all directly connected to the referenced row) is minimized. So, by using sets to implement SQL foreign and primary key relationships, RDM Embedded SQL not only provides optimal performance but does so with less storage requirements than needed in a relational-only implementation. Relational Model Versus Network Model The differences between relational and network model databases are often characterized as being mutually exclusive. But as shown above, from a database organization standpoint, they are compatible because a network model implementation using sets can efficiently be used to implement relational model foreign and primary key relationships. However, the real difference between the two models is in how the data is accessed not in how it is defined (or implemented). P a g e 5

Access to database data in a network model database requires that the application program navigate through set occurrences, one member record occurrence (i.e. row) at a time to locate the desired record occurrence(s). Using a relational database model language (e.g., SQL), a single select statement will perform the needed navigation and, thus, is much simpler. The advantages of the relational model are most significant in performing queries. For storing, modifying, deleting and retrieving individual record occurrences (table rows), however, there is no significant advantage. But only with RDM can you choose which approach is best for your application requirements. Want to know more? Please call us to discuss your database needs or email us at info@raima.com. You may also visit our website for the latest news, product downloads and documentation: www.raima.com Headquarter: 720 Third Avenue Suite 1100, Seattle, WA 98104, USA T: +1 206 748 5300 Europe: Stubbings House, Henley Road, Maidenhead, UK SL6 6QLT: +44 1628 826 800 Copyright Raima Inc., 2012. P a g e 6