Introduction to Relational Database Concepts. Copyright 2011, Oracle. All rights reserved.

Similar documents
Basic Mapping: The Transformation Process. Copyright 2011, Oracle. All rights reserved.

Database Design. 9-2 Basic Mapping: The Transformation Process. Copyright 2015, Oracle and/or its affiliates. All rights reserved.

Database Programming with SQL

Database Programming with SQL

Database Programming with SQL

Database Programming with SQL

Database Programming with SQL

Database Programming with SQL

King Fahd University of Petroleum and Minerals

Database Programming with SQL

Assignment Grading Rubric

Database Management Systems

Database Programming with SQL

Database Foundations. 6-4 Data Manipulation Language (DML) Copyright 2015, Oracle and/or its affiliates. All rights reserved.

Database Foundations. 5-1 Mapping Entities and Attributes. Copyright 2015, Oracle and/or its affiliates. All rights reserved.

Database Design - Section 11. Instructor Guide

Relational Model. IT 5101 Introduction to Database Systems. J.G. Zheng Fall 2011

Recursive Common Table Expressions in Oracle Database 11g Release 2. Iggy Fernandez Database Specialists Session #303

Database Programming with SQL

Updating Column Values and Deleting Rows. Copyright 2008, Oracle. All rights reserved.

Database Design. 1-3 History of the Database. Copyright 2015, Oracle and/or its affiliates. All rights reserved.

Cartesian Product and the Join Operations. Copyright 2008, Oracle. All rights reserved.

Working with Columns, Characters and Rows. Copyright 2008, Oracle. All rights reserved.

Chapter 4. The Relational Model

Using the Set Operators. Copyright 2006, Oracle. All rights reserved.

DEFAULT Values, MERGE, and Multi-Table Inserts. Copyright 2009, Oracle. All rights reserved.

Restricting and Sorting Data. Copyright 2004, Oracle. All rights reserved.

Bsc (Hons) Software Engineering. Examinations for / Semester 1. Resit Examinations for BSE/15A/FT & BSE/16A/FT

Using DDL Statements to Create and Manage Tables. Copyright 2004, Oracle. All rights reserved.

Databases. Purpose Of A Database. To store information

Using DDL Statements to Create and Manage Tables. Copyright 2004, Oracle. All rights reserved.

Advance Database Systems. Joining Concepts in Advanced SQL Lecture# 4

Database Design. 9-3 Relationship Mapping. Copyright 2015, Oracle and/or its affiliates. All rights reserved.

Retrieving Data Using the SQL SELECT Statement. Copyright 2004, Oracle. All rights reserved.

DUE: 9. Create a query that will return the average order total for all Global Fast Foods orders from January 1, 2002, to December 21, 2002.

Objectives. After completing this lesson, you should be able to do the following:

Restricting and Sorting Data. Copyright 2004, Oracle. All rights reserved.

Using DDL Statements to Create and Manage Tables. Copyright 2006, Oracle. All rights reserved.

Displaying Data from Multiple Tables. Copyright 2004, Oracle. All rights reserved.

Graphical Joins in More Detail

SQL Server 2008 Tutorial 3: Database Creation

DATABASE DEVELOPMENT (H4)

EXISTS NOT EXISTS WITH

Database Foundations. 6-3 Data Definition Language (DDL) Copyright 2015, Oracle and/or its affiliates. All rights reserved.

Database Programming - Section 10. Instructor Guide

Creating Other Schema Objects

Product Documentation. InterBase Update 2. Data Definition Guide

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

RETRIEVING DATA USING THE SQL SELECT STATEMENT

Database Systems Relational Model. A.R. Hurson 323 CS Building

Retrieving Data Using the SQL SELECT Statement. Copyright 2009, Oracle. All rights reserved.

Alkérdések II. Copyright 2004, Oracle. All rights reserved.

Manipulating Data. Copyright 2004, Oracle. All rights reserved.

Introduction to Databases

Database Programming with SQL

Department of Computer Science and Information Systems, College of Business and Technology, Morehead State University

Oracle Database 11g: SQL Fundamentals I COPYRIGHTED MATERIAL. PArt

Limit Rows Selected. Copyright 2008, Oracle. All rights reserved.

DATA CONSTRAINT. Prepared By: Dr. Vipul Vekariya

The Relational Model

School of Computing and Information Technology Session: Spring CSCI835 Database Systems (Bridging Subject) Sample class test 23 July 2018

Introduction to Oracle

Introduction to Databases

Database Programming with PL/SQL

Database Programming with PL/SQL

Database Principles: Fundamentals of Design, Implementation, and Management Tenth Edition. Chapter 7 Data Modeling with Entity Relationship Diagrams

Database Design. 9-4 Subtype Mapping. Copyright 2015, Oracle and/or its affiliates. All rights reserved.

Data Definition Guide InterBase 2009

October 29, Copyright 2012 by World Class CAD, LLC. All Rights Reserved.

Getting Information from a Table

RMOUG Training Days 2018

Introduction to MS Access: creating tables, keys, and relationships

Database Logical Design

Outer Join, More on SQL Constraints

Figure 1: Relationship among Three Entities/Tables

KORA. RDBMS Concepts II

Relational Model History. COSC 416 NoSQL Databases. Relational Model (Review) Relation Example. Relational Model Definitions. Relational Integrity

DC62 Database management system JUNE 2013

Database Logical Design

CIS 207 Oracle - Database Programming and SQL HOMEWORK: # 13

Database Management System. * First install Mysql Database or Wamp Server which contains Mysql Databse.

Architecture. Architecture. Introduction to Oracle 10g Express Edition. Help

Data Modelling and Databases. Exercise Session 7: Integrity Constraints

Introduction to Oracle9i: SQL

Chapter 2. DB2 concepts

A database consists of several tables (relations) AccountNum

Database Management System 9

1Z0-007 ineroduction to oracle9l:sql

Relational Model History. COSC 304 Introduction to Database Systems. Relational Model and Algebra. Relational Model Definitions.

Database Foundations. 6-9 Joining Tables Using JOIN. Copyright 2014, Oracle and/or its affiliates. All rights reserved.

Relational Data Model. Christopher Simpkins

Oracle Database SQL Basics

Practical 8. SHANKER SINH VAGHELA BAPU INSTITUTE OF TECHNOLGY Subject: - DBMS Branch: - IT/CE Semester: - 3rd. 1. What does SQL stand for?

Introduction to Relational Databases. Introduction to Relational Databases cont: Introduction to Relational Databases cont: Relational Data structure

Translating an ER Diagram to a Relational Schema

Database Programming with PL/SQL

Physical Design of Relational Databases

Retrieving Data from Multiple Tables

Retrieving Data Using the SQL SELECT Statement. Copyright 2004, Oracle. All rights reserved.

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

Transcription:

Introduction to Relational Database Concepts Copyright 2011, Oracle. All rights reserved.

What Will I Learn? Objectives In this lesson, you will learn to: Define a primary key Define a foreign key Define a column-integrity rule Identify row, column, primary key, unique key, and foreign key given a diagram of a table containing these elements Identify violations of data-integrity rules 2

Why Learn It? Purpose The conceptual data model will be transformed into a relational database design. This means that our entities, attributes, relationships, and unique identifiers will be translated into objects in a relational database. Compare this to a clothing designer that is taking their design from paper and implementing it with fabric. The designer needs to understand how to sew the designs just like you will need to understand the structure of relational database objects. 3

4 Relational Database Illustrated A relational database is a database that is seen by the user as a collection of two-dimensional tables. The table below contains employee data. EMPLOYEES (table name) EMPLOYEE_ID FIRST_NAME LAST_NAME DEPARTMENT_ID Row 100 101 Steven Neena King Kochhar 102 Lex De Haan 200 Jennifer Whalen 10 205 Shelley Higgins 110 Column

Language to Access Data Structured query language (SQL) allows us to access data in relational databases in an efficient way. Instead of going through each row to find the record for employee number 200, we use the following SQL statement: SELECT last_name, department_id FROM employees WHERE employee_id = 200; You can see the result of this statement on the next slide. 5

6 SQL Query Illustrated EMPLOYEES (table name) EMPLOYEE_ID FIRST_NAME LAST_NAME DEPARTMENT_ID 100 Steven King 101 Neena Kochhar 102 Lex De Haan 200 Jennifer Whalen 10 205 Shelley Higgins 110 SELECT last_name, department_id FROM employees WHERE employee_id = 200; LAST_NAME Whalen DEPARTMENT_ID 10

Specific SQL Query To find all the employees in department number, we write a different SQL statement: SELECT * FROM employees WHERE department_id = ; Again, you can see the result on the next slide. 7

Specific SQL Query (continued) EMPLOYEES (table name) EMPLOYEE_ID FIRST_NAME LAST_NAME DEPARTMENT_ID 100 Steven King 101 Neena Kochhar 102 Lex De Haan 200 Jennifer Whalen 10 205 Shelley Higgins 110 SELECT * FROM employees WHERE department_id = ; EMPLOYEES (table name) EMPLOYEE_ID FIRST_NAME LAST_NAME 100 Steven King DEPARTMENT_ID 101 Neena Kochhar 102 Lex De Haan 8

A primary key (PK) is a column or set of columns that uniquely identifies each row in a table. ACCOUNTS BANK_NO 104 104 105 103 105 ACCT_NO 75760 77956 89570 558 75760 BALANCE 12,0050.00 100.10 55,775.00 15,001.85 5.00 DATE_OPENED 21-OCT-89 15-JAN-85 10-MAR-91 22-SEP-03 EMPLOYEES EMPLOYEE_ID FIRST_NAME LAST_NAME 100 Steven King DEPARTMENT_ID 101 Neena Kochhar 102 Lex De Haan 200 Jennifer Whalen 10 205 Shelley Higgins 110 9

Rules Each table should have a primary key, and a primary key must be unique. No part of the primary key can be null. ACCOUNTS BANK_NO 104 104 105 103 105 ACCT_NO 75760 77956 89570 558 75760 BALANCE 12,0050.00 100.10 55,775.00 15,001.85 5.00 DATE_OPENED 21-OCT-89 15-JAN-85 10-MAR-91 22-SEP-03 EMPLOYEES EMPLOYEE_ID FIRST_NAME LAST_NAME 100 Steven King DEPARTMENT_ID 101 Neena Kochhar 102 Lex De Haan 200 Jennifer Whalen 10 205 Shelley Higgins 110 10

Candidates A table can have more than one column or combination of columns that could serve as the table s primary key. Each of these is called a "candidate" key. MEMBERS MEMBER_ID LAST_NAME FIRST_NAME PAYROLL_ID 100 SMITH DANA 21215 310 ADAMS TYLER 59877 210 CHEN LAWRENCE 1101 405 GOMEZ CARLOS 52 378 LOUNGANI NEIL 386 Candidate Key Candidate Key 11

Choose a Candidate Key Select one candidate key to be the primary key for the table. The other candidates become alternate keys (or unique keys). MEMBERS MEMBER_ID LAST_NAME FIRST_NAME PAYROLL_ID 100 SMITH DANA 21215 310 ADAMS TYLER 59877 210 CHEN LAWRENCE 1101 405 GOMEZ CARLOS 52 378 LOUNGANI NEIL 386 Alternate or Unique Key (UK) 12

Foreign Key Foreign Key A foreign key (FK) is a column or combination of columns in one table that refers to a primary key in the same table or another table. EMPLOYEES EMPLOYEE_ID 100 101 102 200 205 FIRST_NAME Steven Neena Lex Jennifer Shelley LAST_NAME King Kochhar De Haan Whalen Higgins DEPARTMENT_ID 10 110 refers to DEPARTMENTS DEPARTMENT_ID 10 20 50 DEPARTMENT_NAME Administration Marketing Shipping 13

Foreign Key Rules If a foreign key is part of a primary key, that FK cannot be NULL. SHELF_NO BOOK_NO SHELF_NO SHELF_NO A6 106 A6 LITTLE WOMEN A8 B24 Q35 15 7987 15 A8 B24 Q35 TALE OF TWO CITIES HARRY POTTER LEARN TO SPEAK SPANISH SHELVES BOOKS Foreign refers to 14

Column Integrity ACCOUNTS A column must contain only values consistent with the defined data format of the column. BANK_NO 104 104 105 103 105 ACCT_NO 75760 77956 89570 558 75760 BALANCE 12,0050.00 100.10 55,775.00 15,001.85 5.00 DATE_OPENED 21-OCT-89 15-JAN-85 10-MAR-91 22-SEP-03 ACCOUNTS Table Definition Column Name BANK_NO ACCT_NO BALANCE DATE_OPENED Data Type Number (5) Number (8) Number (12,2) Date Optionality Not null Not null Not null 15

Summary of Data-Integrity Rules Data-integrity rules (also known as constraints) define the relationally correct state for a database. Data-integrity rules ensure that users can perform only those operations that leave the database in a correct, consistent state. CONSTRAINT TYPE Entity Integrity Referential Integrity Column Integrity User-Defined Integrity EXPLANATION A primary key must be unique, and no part of the primary key can be null A foreign key must match an existing primary key value (or else be null) A column must contain only values consistent with the defined data format of the column The data stored in a database must comply with the rules of the business EXAMPLE The column emp_no in the EMPLOYEES table cannot be null The value in the dept_no column of the EMPLOYEES table must match a value in the dept_no column in the DEPARTMENTS table The value in the balance column of the ACCOUNTS table must be numeric If the value in the balance column of the ACCOUNTS table is below 1.00, we must send a letter to the account owner ( this will need extra programming to enforce) 16

17 Terminology Key terms used in this lesson include: Candidate key Column Foreign key Primary key Relational database Row Unique key

Summary Objectives Summarized In this lesson, you have learned to: Define a primary key Define a foreign key Define a column-integrity rule Identify row, column, primary key, unique key, and foreign key given a diagram of a table containing these elements Identify violations of data-integrity rules 18

Summary Practice Guide The link for the lesson practice guide can be found in the course resources in Section 0. 19