Answers included WORKSHEET: INTEGRITY CONTROL IN RELATIONAL DATABASES



Similar documents
CS2Bh: Current Technologies. Introduction to XML and Relational Databases. The Relational Model. The relational model

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

SQL Simple Queries. Chapter 3.1 V3.0. Napier University Dr Gordon Russell

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

Databasesystemer, forår 2005 IT Universitetet i København. Forelæsning 3: Business rules, constraints & triggers. 3. marts 2005

Databases What the Specification Says

There are five fields or columns, with names and types as shown above.

Module Contact: Dr. Beatriz de la Iglesia, CMP Copyright of the University of East Anglia Version 1

The Entity-Relationship Model

SQL NULL s, Constraints, Triggers

Rose Data Modeler (logical)

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

Chapter 6: Integrity Constraints

Database Design Overview. Conceptual Design ER Model. Entities and Entity Sets. Entity Set Representation. Keys

Data Modeling. Database Systems: The Complete Book Ch ,

Access Tutorial 2: Tables

A. TRUE-FALSE: GROUP 2 PRACTICE EXAMPLES FOR THE REVIEW QUIZ:

DATABASE MANAGEMENT SYSTEMS. Question Bank:

types, but key declarations and constraints Similar CREATE X commands for other schema ëdrop X name" deletes the created element of beer VARCHARè20è,

The Relational Model. Why Study the Relational Model?

Unit 5.1 The Database Concept

A Rational Software Whitepaper

Introduction to Triggers using SQL

CS143 Notes: Views & Authorization

Guide to Upsizing from Access to SQL Server

SQL Data Definition. Database Systems Lecture 5 Natasha Alechina

Implementing and Maintaining Microsoft SQL Server 2008 Integration Services

LSP 121. LSP 121 Math and Tech Literacy II. Simple Databases. Today s Topics. Database Class Schedule. Simple Databases

EECS 647: Introduction to Database Systems

Intermediate SQL C H A P T E R4. Practice Exercises. 4.1 Write the following queries in SQL:

ICAB4136B Use structured query language to create database structures and manipulate data

SQL Tables, Keys, Views, Indexes

Physical Design. Meeting the needs of the users is the gold standard against which we measure our success in creating a database.

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

3. Relational Model and Relational Algebra

MCQs~Databases~Relational Model and Normalization

TIM 50 - Business Information Systems

Databases and BigData

Semantic Errors in SQL Queries: A Quite Complete List

Create a PivotTable or PivotChart report

Lecture 6. SQL, Logical DB Design

Review Entity-Relationship Diagrams and the Relational Model. Data Models. Review. Why Study the Relational Model? Steps in Database Design


SQL Server An Overview

Evaluation Checklist Data Warehouse Automation

Topics. Database Essential Concepts. What s s a Good Database System? Using Database Software. Using Database Software. Types of Database Programs

Software Requirements Specification. Human Resource Management System. Sponsored by Siemens Enterprise Communication. Prepared by InnovaSoft

SQL. by Steven Holzner, Ph.D. ALPHA. A member of Penguin Group (USA) Inc.

Database Management Systems. Chapter 1

IT2305 Database Systems I (Compulsory)

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

LiTH, Tekniska högskolan vid Linköpings universitet 1(7) IDA, Institutionen för datavetenskap Juha Takkinen

The process of database development. Logical model: relational DBMS. Relation

Chapter 5: Logical Database Design and the Relational Model Part 2: Normalization. Introduction to Normalization. Normal Forms.

Introduction to Microsoft Access 2003

Fundamentals of Database Design

IENG2004 Industrial Database and Systems Design. Microsoft Access I. What is Microsoft Access? Architecture of Microsoft Access

Playing with Numbers

Review: Participation Constraints

Ken Goldberg Database Lab Notes. There are three types of relationships: One-to-One (1:1) One-to-Many (1:N) Many-to-Many (M:N).

The SQL Query Language. Creating Relations in SQL. Referential Integrity in SQL. Basic SQL Query. Primary and Candidate Keys in SQL

12 File and Database Concepts 13 File and Database Concepts A many-to-many relationship means that one record in a particular record type can be relat

Database Systems. Lecture 1: Introduction

101 IELTS Speaking Part Two Topic cards about sports, hobbies and free time A- Z

Implementing and Maintaining Microsoft SQL Server 2005 Reporting Services COURSE OVERVIEW AUDIENCE OUTLINE OBJECTIVES PREREQUISITES

Working with the Geodatabase Using SQL

MS SQL Performance (Tuning) Best Practices:

Exercise 1: Relational Model

BCS THE CHARTERED INSTITUTE FOR IT BCS HIGHER EDUCATION QUALIFICATIONS BCS Level 5 Diploma in IT DATABASE SYSTEMS

DbSchema Tutorial with Introduction in SQL Databases

ER modelling, Weak Entities, Class Hierarchies, Aggregation

ETL Process in Data Warehouse. G.Lakshmi Priya & Razia Sultana.A Assistant Professor/IT

ICAEW IT FACULTY TWENTY PRINCIPLES FOR GOOD SPREADSHEET PRACTICE

Training Needs Analysis

Gantt Chart/Diagram Excel Template User Guide

SQL Server Introduction to SQL Server SQL Server 2005 basic tools. SQL Server Configuration Manager. SQL Server services management

Foundations of Business Intelligence: Databases and Information Management

Outline. Data Modeling. Conceptual Design. ER Model Basics: Entities. ER Model Basics: Relationships. Ternary Relationships. Yanlei Diao UMass Amherst

Relational Database Basics Review

MySQL for Beginners Ed 3

Topic: Relationships in ER Diagram and Relationships in MS Access

SAMPLE. The ADA Practical Guide to Social Media Planning. Second Edition

SQL: Queries, Programming, Triggers

14 Databases. Source: Foundations of Computer Science Cengage Learning. Objectives After studying this chapter, the student should be able to:

Example Instances. SQL: Queries, Programming, Triggers. Conceptual Evaluation Strategy. Basic SQL Query. A Note on Range Variables

Section of DBMS Selection & Evaluation Questionnaire

Graham Kemp (telephone , room 6475 EDIT) The examiner will visit the exam room at 15:00 and 17:00.

Tutorial 3 The Relational Database Model

SQL: Queries, Programming, Triggers

Welcome to the topic on Master Data and Documents.

Basics of Dimensional Modeling

Tutorial on Relational Database Design

Schema Design and Normal Forms Sid Name Level Rating Wage Hours

The Relational Data Model: Structure

Course MIS. Foundations of Business Intelligence

Real SQL Programming. Persistent Stored Modules (PSM) PL/SQL Embedded SQL

Concepts of Database Management Seventh Edition. Chapter 6 Database Design 2: Design Method

Transcription:

CS27020: Modelling Persistent Data WORKSHEET: INTEGRITY CONTROL IN RELATIONAL DATABASES Time allowed: 40 minutes Calculators are not allowed in this worksheet. Answer all questions 1. Briefly explain what is meant by each of the following terms. Use suitable examples to illustrate your explanations. Enterprise rule (also known as business rule) Data integrity Integrity constraint Enterprise rule: empirical constraint on real world entities and attributes. Examples: Each pallet contains 5184 bottles (a real example, referring to supplies of an antiviral); a student is normally allowed at most two attempts at a module examination. Data integrity: the data in a database models the real world; the database corresponds to reality. For example, a person has exactly one date of birth. Integrity constraint: a constraint on the values or combinations of values that are allowed to be entered into a database. For example, no two distinct vehicles are allowed to have the same vehicle identification number is a constraint that allows vehicle identification number to identify a particular vehicle record. Page 1 of 7

2. Briefly explain the terms domain, candidate key and foreign key as used in the relational data model. A domain is the set of possible values for an attribute; it is the type of the attribute. In a relational database, a domain is the set of possible values for the cells in a column of a table. A candidate key is a collection of attributes whose combined values are different for each tuple in a relation. A candidate key is also minimal in the sense that no subset of the candidate key will identify tuples in this way. A foreign key is a collection of attributes from one relation that constitutes a candidate key for another relation. The values of the foreign key attributes in the first relation must also be present in some tuple of the second relation. 3. As well as domains, candidate keys and foreign keys, a database management system must provide other kinds of integrity constraints. Why are other kinds of constraint needed? Give an example of a constraint that cannot be modelled using domains, candidate keys and foreign keys. Other kinds of constraint are needed because domains and key constraints are not sufficient to capture all the different kinds of enterprise rule that need to be modelled in a database. For example, the constraint every sheep farmer owns at least one sheep cannot be represented using domains, foreign keys and candidate keys. In general, minimal cardinality constraints (1.. cardinalities) demand more than domains and foreign and candidate keys. 4. What facilities might be provided by a relational database management systems to uphold such constraints? Facilities provided by relational database management systems include checks, assertions, functions, procedures and triggers. 5. Integrity constraints can be enforced in application code, or by the database management system. Why is it usually better to have the database management system enforce integrity constraints? When constraints are enforced by applications, every application that can modify the table(s) in question must implement them. It can be difficult to ensure that constraints are enforced when applications are written over a long period of time. Page 2 of 7

6. A role playing game includes a table of data about characters. The table has an attribute kind. The values that can be given to kind are monster, wizard, hero, seer. a) Write SQL statements to enforce this in three different ways: (i) using an enumerated data type; CREATE TYPE character_kind AS ENUM ( monster, wizard, hero, seer ); CREATE TABLE character (..., kind character_kind, etc ); (ii) using a check constraint; CREATE TABLE character (..., kind text CHECK (kind in ( monster, wizard, hero, seer )), etc ); (iii) using a foreign key reference. CREATE TABLE character_kind ( kind text primary key ); INSERT INTO character_kind (kind) VALUES (monster), (wizard), ( hero), ( seer ); CREATE TABLE character (..., kind text REFERENCES character_kind(kind) ); Page 3 of 7

b) What are the relative merits of these three approaches? Points including the following are likely: Enumerated type and foreign key reference allow constraint to be implemented once, and reused in many tables. Both these approaches allow a simple query to display values to be entered into the table via form widget. However, acceptable values are not immediately visible in the table definition when either of these approaches is used. Cannot use native string operators such as like with enumerated types (this restriction is not true of every DBMS.) Using a foreign key reference facilitates modification of the list of acceptable values. A check constraint is immediately visible in a table definition. Values shown in the check constraint can be used with native string operators. A check constraint is not available for use in other tables. Page 4 of 7

7. In a supermarket chain, Bubble Beans, popular with toast lovers, are only moved between the warehouse and the stores on pallets of 400 cartons. A simplified version of the warehouse stock relation is as follows: warehouse stock{ item code:integer, item name:text, quantity:integer} where item code is the primary key. Write an SQL definition for this table. Your definition should support the rules if two items have the same item name, then they also have the same item code, and quantity is always a multiple of 400 if item name is Bubble Beans. CREATE TABLE warehouse_stock( item_code integer PRIMARY KEY, item_name text, quantity integer, UNIQUE (item_code,item_name), CONSTRAINT valid_quantity CHECK ((NOT(item_name LIKE Bubble BeanS )) OR (mod(quantity,400) = 0))); Page 5 of 7

8. Llandwp Music Club caters for for singing ensembles. Each singer sings with at least one and at most three ensembles. Each ensemble has at least two and at most twenty singers. These enterprise rules are illustrated in the diagram: Singer Group 2..20 1..3 a) Suppose application code is to be written to create and delete singer and ensemble records, and to move singers from ensemble to ensemble. List the checks that the application code would need to include in order to enforce the enterprise rules shown in the diagram. A good answer will include points like these: when creating a singer, also place the singer in a ensemble; before adding a singer to a ensemble, check whether or not the singer is already a member of three ensembles and that the ensemble has not already got twenty singers; before deletinging a singer, check that this will not cause an ensemble to be reduced to fewer than two singers; when creating a new ensemble, add at least two singers to the ensemble; before deleting an ensemble, remove all the singers from that ensemble; this may involve deleting singers, if they are not members of a second ensemble; when moving a singer from one ensemble to another, check that the first ensemble is not left with fewer than two singers, and the second will not have more than twenty singers. Page 6 of 7

b) Outline how you would enforce the enterprise rules using SQL functions and triggers. Assume that a database has been created that includes three tables: one for the singers, one for the ensembles and one for the relationship between singers and ensembles. There is no need to write the procedural SQL code; an outline in English is sufficient. A good answer should identify the necessary triggers and functions. If the following points were fleshed out they would form a very good answer. Functions to check the cardinality constraints; Functions to create and delete new singers and ensembles; A function to change the relationship between singers and ensembles; Triggers that execute the functions to check the cardinality constraints when singers are added or deleted, or moved between ensembles, or when ensembles are created or deleted. Page 7 of 7