Primary Keys Uniqueness of Table Rows

Slides:



Advertisements
Similar presentations
Relational Database Design UNIT II 1. 2 Advantages of Using Database Systems Centralized control of a firm’s data Redundancy can be reduced (avoid keeping.
Advertisements

Advanced Data Modeling
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 6 Advanced Data Modeling.
Database Systems: Design, Implementation, and Management Tenth Edition
Chapter 6 Advanced Data Modelling
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 6 Advanced Data Modeling.
Systems Development Life Cycle
The Relational Database Model:
Lecture 2 The Relational Model. Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical relations.
Database Systems: Design, Implementation, and Management Tenth Edition Chapter 5 Advanced Data Modeling.
Database Management System Lecture 6 The Relational Database Model – Keys, Integrity Rules.
Fundamentals of Relational Database Yong Choi School of Business CSUB, Bakersfield.
IMS 6217: Primary Key Reference 1 Dr. Lawrence West, MIS Dept., University of Central Florida Primary Keys Uniqueness of Table Rows Identifier.
Concepts of Relational Databases. Fundamental Concepts Relational data model – A data model representing data in the form of tables Relations – A 2-dimensional.
Chapter 8 Data Modeling Advanced Concepts Database Principles: Fundamentals of Design, Implementation, and Management Tenth Edition.
IMS 4212: Data Modeling—Attributes 1 Dr. Lawrence West, Management Dept., University of Central Florida Attributes and Domains Nonkey.
Slide Chapter 5 The Relational Data Model and Relational Database Constraints.
1 Functional Dependencies and Normalization Chapter 15.
Copyright © 2009 Pearson Education, Inc. Publishing as Prentice Hall Chapter 9 Designing Databases 9.1.
IMS 6217: Database Design & Entities 1 Dr. Lawrence West, MIS Dept., University of Central Florida Database Design--Topics DB Design.
Logical Database Design and Relational Data Model Muhammad Nasir
IMS 6217: Introduction to Data Modeling 1 Dr. Lawrence West, MIS Department, University of Central Florida Introduction to Data Modeling—Topics.
Lecture # 14 Chapter # 5 The Relational Data Model and Relational Database Constraints Database Systems.
Standards and Conventions
Database Constraints ICT 011. Database Constraints Database constraints are restrictions on the contents of the database or on database operations Database.
COP Introduction to Database Structures
CompSci 280 S Introduction to Software Development
Let try to identify the conectivity of these entity relationship
Logical Database Design and the Rational Model
Understanding Data Storage
Implementing an REA Model in a Relational Database
Database Constraints Ashima Wadhwa.
INLS 623 – Database Normalization
Chapter 4 Logical Database Design and the Relational Model
Client/Server Databases and the Oracle 10g Relational Database
Record Storage, File Organization, and Indexes
Attributes and Domains
MIS2502: Data Analytics Relational Data Modeling
The Relational Data Model and Relational Database Constraints
Chapter 5: Logical Database Design and the Relational Model
Tables and Their Characteristics
Relational Database Design by Dr. S. Sridhar, Ph. D
Entity-Relationship Model
Lecture 2 The Relational Model
Primary Keys—Topics Uniqueness of Table Rows
Lecture # 13 (After 1st Exam)
Example Question–Is this relation Well Structured? Student
Chapter 3 The Relational Database Model
Order Database – ER Diagram
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 6 Normalization of Database Tables
MIS2502: Data Analytics Relational Data Modeling
Chapter 4 The Relational Model Pearson Education © 2009.
Primary key Introduction Introduction: A primary key, also called a primary keyword, is a key in a relational database that is unique for each record.
The Relational Model Transparencies
Database solutions Chosen aspects of the relational model Marzena Nowakowska Faculty of Management and Computer Modelling Kielce University of Technology.
Session 2 Welcome: The fifth learning sequence
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 4 The Relational Model Pearson Education © 2009.
Relational Database Design
DCT 2053 DATABASE CONCEPT Chapter 2.2 CONTINUE
Data Definition Language
Data Definition Language
Database Design: Relational Model
Chapter 4 The Relational Model Pearson Education © 2009.
Attributes and Domains
Database Management system
Database Management system
Review of Week 3 Relation Transforming ERD into Relations
Presentation transcript:

Primary Keys Uniqueness of Table Rows Identifier Attributes and Primary Keys Composite Identifiers Natural and Artificial Identifiers and Autogenerated Primary Keys Candidate Keys and Alternate Keys Problem Keys Diagraming Tables with Key Attributes

Uniqueness of Table Rows Remember our twin goals of minimizing storage space and reducing data redundancy A duplicate record (occurrence) in a table violates this rule Because any record represents one real world occurrence of the thing the entity defines if there is a duplicate record there must be a duplicate occurrence But each occurrence is unique so duplicate records are wasted space—one record is enough

Uniqueness of Table Rows and Update Anomalies An “update anomaly” occurs when data is not updated correctly Duplicate records affect data accuracy through update anomalies and processing efficiency Occur when duplicate data exists and not all matching records are updated when a change is needed May be two records for the same customer with different addresses All records must be checked (since there could be duplicates) instead of stopping when the matching record is found

A Theory for the Importance of Primary Keys If a subset of attributes (including a single attribute) can be guaranteed to have unique values in a single table… …then each record in the table is guaranteed to be unique… …even if there are duplicates for the values of other attributes Student ID is unique to each student Roommates will share address attribute values

Identifier Attributes Identifier Attribute(s): An attribute or set of attribute(s) whose value(s) uniquely identify each occurrence of an entity Identifier Attributes are forced to be unique within a table SSN for student or faculty VIN for an automobile SKU for a retail product We will refer to Identifier Attributes at design time and these will become Primary Keys upon implementation (after some analysis)

Identifier Attributes Define Entities A Vehicle Identification Number (VIN) identifies one and only one instance of an automobile Since only an automobile can be identified by a VIN, an entity with VIN as an identifier attribute can only contain occurrences of automobiles The VIN then identifies a car but defines the entity What entities do these attributes define? Social Security Number Radio Call Letters (WMFE) Universal Product Code (UPC) Identifier attributes can never, ever be null

Composite Identifiers Some entities need more than one attribute to form a unique value DepartmentCode & CourseNumber Both attributes combine to be unique and identify each occurrence and define the entity Duplicates are allowed within each attribute Any MIS course has an “ISM” prefix There can be an English course with “4212” as the course number The combination of values (“ISM 4212”) must be unique

Composite Identifiers (cont) What is the natural PK of our section of this course? Of the fact that you are enrolled in this course? What entities are identified by the following values? RegisterNumber & StartTime (DateTime value) VIN and SSN Building & RoomNumber (UCF database) AptNum & StartDate ProductID & SaleID

“Natural” and “Artificial” Identifiers Most PKs are “artificial” or “generated” SSN – StudentID VIN – CourseNum SerialNumber – LicensePlateNum & State Some PKs are (more) “natural” MagazineTitle & PublicationDate Section Identifier PK The distinction isn’t particularly important

Autogenerated PKs An important class of artificial PKs are the anuogenerated, autonumber, or “Identity” attributes DBMS can be configured to automatically generate a unique sequential number for each new record added to a table By definition these values are unique and so can be a PK

Candidate Keys Some entities may have more than one attribute or sets of attributes that can serve as a PK VIN ParkingDecalNum & Year State & TagNum How is a house identified? Often a “natural” PK is cumbersome and an artificial PK, especially an autonumber, is introduced One candidate key is selected to be the PK Nonselected candidate keys become “alternate keys”

Some Problem PKs People’s names are horrible choices for PKs (Is there a “natural” PK for a person?) Avoid PKs that change frequently All things being equal, choose the simplest candidate key to be the PK Always ensure that you PK defines the entity that you have in mind

A Data Model Segment

Documenting Identifier Attributes (cont.) Identifier attributes are underlined in an ER diagram

PKs and Other Attributes in SQL Server Diagram Composite PK Single-attribute PK