Database Design Process. ER Model. Goals. Relational Model. SQL - The Language of Databases. IT420: Database Management and Organization



Similar documents
Database Design Process

Database Design Process

How To Create A Table In Sql (Ahem)

SQL 2: GETTING INFORMATION INTO A DATABASE. MIS2502 Data Analytics

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

IT2304: Database Systems 1 (DBS 1)

IT2305 Database Systems I (Compulsory)

EECS 647: Introduction to Database Systems

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

Databases and BigData

Database Design. Database Design I: The Entity-Relationship Model. Entity Type (con t) Chapter 4. Entity: an object that is involved in the enterprise

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

Fundamentals of Database Design

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

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

CSC 443 Data Base Management Systems. Basic SQL

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

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

Introduction to SQL and database objects

Data Modeling. Database Systems: The Complete Book Ch ,

Database Migration : An In Depth look!!

Databases Model the Real World. The Entity- Relationship Model. Conceptual Design. Steps in Database Design. ER Model Basics. ER Model Basics (Contd.

Lecture 6. SQL, Logical DB Design

Introduction to SQL ( )

Modern Systems Analysis and Design

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

Chapter 7 Data Modeling Using the Entity- Relationship (ER) Model

B.1 Database Design and Definition

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

Databases What the Specification Says

Relational Databases. Christopher Simpkins

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

DATABASE DESIGN. - Developing database and information systems is performed using a development lifecycle, which consists of a series of steps.

SQL Server Table Design - Best Practices


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

Conceptual Design Using the Entity-Relationship (ER) Model

Information Systems Modelling Information Systems I: Databases

The Entity-Relationship Model

We know how to query a database using SQL. A set of tables and their schemas are given Data are properly loaded

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

Question 1. Relational Data Model [17 marks] Question 2. SQL and Relational Algebra [31 marks]

Relational Database Basics Review

6 CHAPTER. Relational Database Management Systems and SQL Chapter Objectives In this chapter you will learn the following:

The Relational Model. Why Study the Relational Model?

A Rational Software Whitepaper

SQL NULL s, Constraints, Triggers

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

Review: Participation Constraints

COMP 378 Database Systems Notes for Chapter 7 of Database System Concepts Database Design and the Entity-Relationship Model

CSI 2132 Lab 3. Outline 09/02/2012. More on SQL. Destroying and Altering Relations. Exercise: DROP TABLE ALTER TABLE SELECT

CSC 742 Database Management Systems

Advance DBMS. Structured Query Language (SQL)

Chapter 2: Entity-Relationship Model. Entity Sets. " Example: specific person, company, event, plant

Relationele Databases 2002/2003

Data Modeling Basics

Designing a Database Schema

Structured Query Language. Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics

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

Database Development and Management with SQL

full file at

!"# $ %& '( ! %& $ ' &)* + ! * $, $ (, ( '! -,) (# *&23. mysql> select * from from clienti;

Tutorial on Relational Database Design

Database Query 1: SQL Basics

Oracle Database 10g Express

DATABASE MANAGEMENT SYSTEMS. Question Bank:

SQL. Short introduction

Chapter 2: Entity-Relationship Model

Relational Database Concepts

Schema Evolution in SQL-99 and Commercial (Object-)Relational DBMS

Information Systems SQL. Nikolaj Popov

SQL Data Definition. Database Systems Lecture 5 Natasha Alechina

Teach Yourself InterBase

Section of DBMS Selection & Evaluation Questionnaire

Database Design. Goal: specification of database schema Methodology: E-R Model is viewed as a set of

Chapter 2: Entity-Relationship Model. E-R R Diagrams

A Tool for Generating Relational Database Schema from EER Diagram

2. Conceptual Modeling using the Entity-Relationship Model

Database Design and Programming

Bridge from Entity Relationship modeling to creating SQL databases, tables, & relations

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

Introduction This document s purpose is to define Microsoft SQL server database design standards.

DbSchema Tutorial with Introduction in SQL Databases

A brief overview of developing a conceptual data model as the first step in creating a relational database.

Entity-Relationship Model

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

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

The Relational Data Model: Structure

Requirement Analysis & Conceptual Database Design. Problem analysis Entity Relationship notation Integrity constraints Generalization

2/3/04 Doc 7 SQL Part 1 slide # 1

Announcements. SQL is hot! Facebook. Goal. Database Design Process. IT420: Database Management and Organization. Normalization (Chapter 3)

BCA. Database Management System

5. CHANGING STRUCTURE AND DATA

THE ENTITY- RELATIONSHIP (ER) MODEL CHAPTER 7 (6/E) CHAPTER 3 (5/E)

Database Design and Normalization

SQL Server An Overview

Database Design Process. Databases - Entity-Relationship Modelling. Requirements Analysis. Database Design

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

Business Rules Modeling for Business Process Events: An Oracle Prototype

Transcription:

Database Design Process IT420: Database Management and Organization Entity-Relationship Model to Relational Model (Chapter 6 Requirements analysis Conceptual design: Entity-Relationship Model Logical design: transform ER model into relational schema Schema refinement: Normalization Physical tuning 1 2 Goals Transform ER model to relational model Write SQL statements to create tables ER Model Entities, attributes, identifiers Weak entities ID-dependent entities - identifying relationships HAS-A Relationships Degree: binary, ternary Maximum cardinality: 1:1, 1:N, N:M Minimum cardinality: O-O, O-M, M-O, M-M IS-A Relationships (Super-type / sub-type Inclusive, Exclusive VERY IMPORTANT to design a good model! 3 4 Relational Model Tables Integrity constraints Primary key Candidate key Foreign key SQL - The Language of Databases Developed by IBM in the 1970s Create and process database data SQL programming is a critical skill!!! 5 6 1

ER to Relational Specify logic for enforcing minimum cardinalities Create a Table for Each Entity CREATE TABLE statement is used for creating relations/tables Each column is described with three parts: column name data type optional constraints 7 9 Specify Data Types Specify Null Status Choose the most specific data type possible!!! Generic Data Types: CHAR(n VARCHAR(n DATE TIME MONEY INTEGER DECIMAL EmployeeNumber integer, EmployeeName char(50, Phone char(15, Email char(50, HireDate date, ReviewDate date 10 Null status: whether or not the value of the column can be NULL EmployeeNumber integer NOT NULL, EmployeeName char (50 NOT NULL, Phone char (15 NULL, Email char(50 NULL, HireDate date NOT NULL, ReviewDate date NULL 11 Specify Default Values Default value - value supplied by the DBMS, if no value is specified when a row is inserted Syntax/support depends on DBMS EmployeeNumber integer NOT NULL, EmployeeName char (50 NOT NULL, Phone char (15 NULL, Email char(50 NULL, HireDate date NOT NULL DEFAULT (getdate(, ReviewDate date NULL 12 Specify Other Data Constraints Data constraints are limitations on data values Name for EmployeeNumber integer NOT NULL, constraint EmployeeName char (50 NOT NULL, Phone char (15 NULL, Email char(50 NULL, HireDate date NOT NULL DEFAULT (getdate(, ReviewDate date NULL, CONSTRAINT Check_Email CHECK (Email LIKE %@gmail.com 14 2

Specify Primary Key Specify Alternate Keys Entity identifier primary key (usually EmployeeNumber integer NOT NULL, EmployeeName char (50 NOT NULL, Phone char (15 NULL, Email char(50 NULL, HireDate date NOT NULL DEFAULT (getdate(, ReviewDate date NULL, CONSTRAINT Check_Email CHECK (Email LIKE %@gmail.com, CONSTRAINT PK_Employee PRIMARY KEY (EmployeeNumber 16 Alternate keys: alternate identifiers of unique rows in a table EmployeeNumber integer NOT NULL, EmployeeName char (50 NOT NULL, Phone char (15 NULL, Email char(50 NULL, HireDate date NOT NULL DEFAULT (getdate(, ReviewDate date NULL, CONSTRAINT Check_Email CHECK (Email LIKE %@gmail.com, CONSTRAINT PK_Employee PRIMARY KEY (EmployeeNumber, CONSTRAINT AK_Email UNIQUE (Email, CONSTRAINT AK_ENamePhone UNIQUE (EmployeeName, Phone 17 ER to Relational Specify logic for enforcing minimum cardinalities 1:1 Strong Entity Relationships Place the key of one entity in the other entity as a foreign key: Either design will work no parent, no child Minimum cardinality considerations may be important: O-M will require a different design that M-O 18 19 1:1 Strong Entity Relationships CREATE TABLE CLUB_MEMBER( MemberNumber integer PRIMARY KEY, MemberName char(50, Phone char(15, Email char(50 CREATE TABLE LOCKER( LockerNumber integer PRIMARY KEY, LockerRoom integer, LockerSize integer, MemberNumber integer NULL, CONSTRAINT FK_Member FOREIGN KEY (MemberNumber REFERENCES CLUB_MEMBER(MemberNumber, CONSTRAINT Unique_Member UNIQUE(MemberNumber 1:1 Strong Entity Relationships CREATE TABLE CLUB_MEMBER( MemberNumber integer PRIMARY KEY MemberName char(50, Phone char(15, Email char(50, LockerNumber integer NULL, CONSTRAINT FK_Locker FOREIGN KEY (LockerNumber REFERENCES LOCKER(LockerNumber, CONSTRAINT Unique_Locker UNIQUE(LockerNumber CREATE TABLE LOCKER( LockerNumber integer PRIMARY KEY, LockerRoom integer, LockerSize integer 21 22 3

1:N Relationships Place the key of the parent in the child 1:N Strong Entity Relationships 23 CREATE TABLE COMPANY( CompanyName char(50 PRIMARY KEY, City char(50, Country char(50, Volume decimal CREATE TABLE DEPARTMENT( DepartmentName char(50 PRIMARY KEY, BudgetCode char(5, MailStop integer, CompanyName char(50 NOT NULL, CONSTRAINT FK_Company FOREIGN KEY (CompanyName REFERENCES COMPANY (CompanyName 24 1:N Identifying Relationship CREATE TABLE BUILDING( BuildingName char(50 PRIMARY KEY, Street varchar(50, City char(50, State char(30, Zip integer CREATE TABLE APARTMENT( ApartmentNumber integer NOT NULL, BuildingName char(50 NOT NULL, NumberBedrooms integer, NumberBaths integer, MonthlyRent decimal, CONSTRAINT PK_Apartment PRIMARY KEY (BuildingName, ApartmentNumber, CONSTRAINT FK_Building FOREIGN KEY (BuildingName REFERENCES BUILDING (BuildingName 25 N:M Strong Entity Relationships In an N:M relationship there is no place for the foreign key in either table: A COMPANY may supply many PARTs A PART may be supplied by many COMPANYs 26 N:M Strong Entity Relationships Create an intersection table: The primary keys of each table composite primary key for intersection table Each table s primary key becomes a foreign key linking back to that table 27 N:M Strong Entity Relationships CREATE TABLE COMPANY( CompanyName char(50 PRIMARY KEY, City char(50, Country char(50, Volume decimal PART( PartNumber integer PRIMARY KEY, PartName char(50, SalesPrice decimal, ReOrderQuantity integer, QuantityOnHand integer COMPANY_PART( CompanyName char(50 NOT NULL, PartNumber integer NOT NULL, CONSTRAINT PK_CompPart PRIMARY KEY (CompanyName, PartNumber, CONSTRAINT FK_Company FOREIGN KEY (CompanyName REFERENCES COMPANY (CompanyName, CONSTRAINT FK_Part FOREIGN KEY (PartNumber REFERENCES PART (PartNumber 28 4

Subtype Relationships ER to Relational CREATE TABLE EMPLOYEE( CREATE TABLE MANAGER( MgrTrainingDate date, Specify logic for enforcing minimum ManagerLevel integer, CONSTRAINT FK_Emp FOREIGN KEY cardinalities (EmployeeNumber REFERENCES EMPLOYEE (EmployeeNumber CREATE TABLE DB_ADMIN( DB_Name char(50, DBMS char(50, CONSTRAINT FK_Emp FOREIGN KEY (EmployeeNumber REFERENCES EMPLOYEE (EmployeeNumber 29 30 FOREIGN KEY Constraints FOREIGN KEY Constraints DEPARTMENTS DepartmentName: char(18 Phone: char(18 Building: char(18 Room: integer D:SN U:C Majors I:SN U:SN STUDENTS StudentNumber: integer StudentLastName: char(18 StudentFirstName: char(18 Email: varchar(50 PhoneNumber: char(18 DepartmentName: char(18 (FK DepartmentName Student Number 190 673 312 Mathematics History Computer Science Student LastName Smith Doe Doe Student FirstName John Jane Bob Phone 410-293-4573 410-293-2255 410-293-6800 Email jsmith@usna.edu jdoe@usna.edu bred@usna.edu Building Michelson Hall Sampson Hall Michelson Hall PhoneNumber 410-431-3456 443-451-7865 CREATE TABLE Departments (DepartmentName char(18, Phone char(18 NOT NULL, Building char(18, Room integer, PRIMARY KEY (DepartmentName Room 308 120 340 MajorDepartmentName Computer Science Mathematics 31 4 options on deletes and updates NO ACTION (default option CASCADE SET NULL SET DEFAULT CREATE TABLE Students (StudentNumber integer, StudentLastName char(18 NOT NULL, StudentFirstName char(18 NOT NULL, Email char(50, PhoneNumber char(18, MajorDepartmentName char(18, PRIMARY KEY (StudentNumber, UNIQUE(Email, CONSTRAINT FK_Dept FOREIGN KEY (MajorDepartmentName REFERENCES Departments (DepartmentName ON DELETE SET NULL ON UPDATE CASCADE 32 Enforcing Mandatory Parent DEPARTMENT (DepartmentName, BudgetCode, ManagerName EmployeeName char(50, DepartmentName char(50 NOT NULL, CONSTRAINT FK_Dept FOREIGN KEY(DepartmentName REFERENCES DEPARTMENT(DepartmentName ON DELETE NO ACTION ON UPDATE CASCADE Enforcing Mandatory Child More difficult to enforce (write code triggers DEPARTMENT (DepartmentName, BudgetCode, ManagerName EMPLOYEE Tricky: (EmployeeNumber, EmployeeName, DepartmentName A department must have some employee EMPLOYEE has DepartmentName as FK, NOT NULL 33 34 5

ER to Relational - Summary Specify primary and alternate keys Specify column types, null status, default values, constraints Place the key of the parent in the child Create intersection tables Specify logic for enforcing minimum cardinalities Actions for insert, delete, update : University ER Data Model Chaired By /Chairs 35 36 37 38 39 40 6

41 43 Representing Ternary and Higher- Order Relationships Transform them in binary relationship Apply the known procedure to transform in relational model 45 47 ER to Relational - Summary Specify primary and alternate keys Specify column types, null status, default values, constraints Place the key of the parent in the child Create intersection tables Specify logic for enforcing minimum cardinalities Actions for insert, delete, update 48 SQL: Creating Tables CREATE TABLE table_name( column_name1 column_type1 [constraints1],, [[CONSTRAINT constraint_name] table_constraint] Table constraints: NULL/NOT NULL PRIMARY KEY (columns UNIQUE (columns CHECK (conditions FOREIGN KEY (local_columns REFERENCES foreign_table (foreign_columns [ON DELETE action_d ON UPDATE action_u] Specify surrogate key in SQL Server: column_name int_type IDENTITY (seed, increment 49 7