Escolar Documentos
Profissional Documentos
Cultura Documentos
9-1
Introduction to Relational Database Concepts
DDS9L1 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 3
Introduction to Relational Database Concepts
Purpose
DDS9L1 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 4
Introduction to Relational Database Concepts
Relational Database Illustrated
Column
DDS9L1 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 5
Introduction to Relational Database Concepts
Language to Access Data
• You can see the result of this statement on the next slide.
DDS9L1 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 6
Introduction to Relational Database Concepts
SQL Query Illustrated
EMPLOYEES (table name)
LAST_NAME DEPARTMENT_ID
Whalen 10
DDS9L1 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 7
Introduction to Relational Database Concepts
Specific SQL Query
DDS9L1 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 8
Introduction to Relational Database Concepts
Specific SQL QueryEMPLOYEES (table name)
EMPLOYEE_ID FIRST_NAME LAST_NAME ... DEPARTMENT_ID
SELECT *
FROM employees
WHERE department_id = 90;
DDS9L1 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 9
Introduction to Relational Database Concepts
Primary Key ACCOUNTS
BANK_NO ACCT_NO BALANCE DATE_OPENED
104 75760 12,0050.00 21-OCT-89
• A primary key (PK) is a 104 77956 100.10
column or set of 105 89570 55,775.00 15-JAN-85
columns that uniquely 103 55890 15,001.85 10-MAR-91
identifies each row in a 105 75760 5.00 22-SEP-03
table.
Multiple Column Primary Key
EMPLOYEES
EMPLOYEE_ID FIRST_NAME LAST_NAME ... DEPARTMENT_ID
100 Steven King ... 90
101 Neena Kochhar ... 90
102 Lex De Haan ... 90
200 Jennifer Whalen ... 10
205 Shelley Higgins ... 110
Single Column Primary Key
DDS9L1 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 10
Introduction to Relational Database Concepts
Primary Key ACCOUNTS
BANK_NO ACCT_NO BALANCE DATE_OPENED
104 75760 12,0050.00 21-OCT-89
• Each table should have 104 77956 100.10
a primary key, and a 105 89570 55,775.00 15-JAN-85
primary key must be 103 55890 15,001.85 10-MAR-91
unique. 105 75760 5.00 22-SEP-03
DDS9L1 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 11
Introduction to Relational Database Concepts
Primary Key ACCOUNTS
BANK_NO ACCT_NO BALANCE DATE_OPENED
104 75760 12,0050.00 21-OCT-89
• No part of the primary 104 77956 100.10
key can be null. 105 89570 55,775.00 15-JAN-85
103 55890 15,001.85 10-MAR-91
105 75760 5.00 22-SEP-03
DDS9L1 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 12
Introduction to Relational Database Concepts
Primary Key Candidates
DDS9L1 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 13
Introduction to Relational Database Concepts
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 90386
DDS9L1 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 14
Introduction to Relational Database Concepts
Foreign Key Foreign Key
EMPLOYEES
Primary Key
DDS9L1 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 15
Introduction to Relational Database Concepts
Foreign Key Rules
PK links to its FK
DDS9L1 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 16
Introduction to Relational Database Concepts
Column Integrity
ACCOUNTS
• A column must
BANK_NO ACCT_NO BALANCE DATE_OPENED
contain only
104 75760 12,0050.00 21-OCT-1989
values that are 104 77956 100.10
consistent with 105 89570 55,775.00 15-JAN-1985
the defined 103 55890 15,001.85 10-MAR-1991
data format of 105 75760 5.00 22-SEP-2003
the column.
ACCOUNTS Table Definition
Column Name Data Type Optionality
DATE_OPENED Date
DDS9L1 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 17
Introduction to Relational Database Concepts
Summary of Data-Integrity Rules
DDS9L1 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 18
Introduction to Relational Database Concepts
Summary of Data-Integrity Rules
DDS9L1 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 19
Introduction to Relational Database Concepts
Terminology
DDS9L1 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 20
Introduction to Relational Database Concepts
Summary
DDS9L1 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 21
Introduction to Relational Database Concepts