Primary Keys—Topics Uniqueness of Table Rows

Slides:



Advertisements
Similar presentations
Advanced Data Modeling
Advertisements

Chapter 6 Advanced Data Modelling
The Relational Database Model:
Database Management System Lecture 6 The Relational Database Model – Keys, Integrity Rules.
DATABASES Pindaro Demertzoglou – Lally School of Management and Technology.
Lecture 7 Integrity & Veracity UFCE8K-15-M: Data Management.
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.
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.
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
INFORMATION TECHNOLOGY DATABASE MANAGEMENT. A database is a collection of information organized to provide efficient retrieval. The collected information.
Standards and Conventions
COP Introduction to Database Structures
Database Design Chapters 17 and 18.
Getting started with Accurately Storing Data
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 5 Database Design
Databases Chapter 9 Asfia Rahman.
Chapter 4 Logical Database Design and the Relational Model
Managing Tables, Data Integrity, Constraints by Adrienne Watt
Client/Server Databases and the Oracle 10g Relational Database
Record Storage, File Organization, and Indexes
Attributes and Domains
Normalization Karolina muszyńska
MIS2502: Data Analytics Relational Data Modeling
Relational Database Design by Dr. S. Sridhar, Ph. D
Attributes and Domains
Primary Keys Uniqueness of Table Rows
Entity-Relationship Model
Lecture 2 The Relational Model
Lecture # 13 (After 1st Exam)
Example Question–Is this relation Well Structured? Student
Database Management  .
CIS 336 Competitive Success/snaptutorial.com
CIS 336 Education for Service-- snaptutorial.com.
CIS 336 Teaching Effectively-- snaptutorial.com
COS 346 Day 8.
CHAPTER 5: PHYSICAL DATABASE DESIGN AND PERFORMANCE
Chapter 3 The Relational Database Model
Database Fundamentals
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
IST 318 Database Administration
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
Relational Database Design
DCT 2053 DATABASE CONCEPT Chapter 2.2 CONTINUE
Data Definition Language
Relationships—Topics
Data Definition Language
Database Design: Relational Model
Relationship Problems—Topics
Attributes and Domains
INSTRUCTOR: MRS T.G. ZHOU
Database Management system
Database Management system
Relationships—Topics
Presentation transcript:

Primary Keys—Topics 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

Identify “Information Elements” Identify Entities Database Design Steps Identify “Information Elements” Identify Entities Identify Primary Keys Identify Relationships Fix Relationship Problems Identify Non-Key Attributes Fix Attribute Problems Address Performance Issues Build Application Objects (stored procedures, views) Design Reports List is not strictly sequential Some steps performed recursively Some steps require returning to previous steps

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

Unique 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 also 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 HMI course has an “HMI” prefix There can be an English course with “6117” as the course number The combination of values (“HIM 6117”) 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 A globally unique alphanumeric (nonsequential) value 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 (e-mail) Phone numbers (not unique, change) All things being equal, choose the simplest candidate key to be the PK Always ensure that your PK defines the entity that you have in mind (Can a SSN change?)

Identifier Attribute (Primary Key) Exercise Pause the video. You will need your list of entities created in the database design video Pick at least three entities and create an Identifier attribute/PK consistent with the entity name and description for each entity. Is there a natural PK? Is an artificial PK needed (especially autonumber)? Are there alternate identifier attribute sets (candidate keys)? Post your results

A Data Model Segment

PKs in SQL Server Diagram Composite PK Single-attribute PK