MySQL from the scratch
MySQL 11 - Entity Integrity
Hide/Show description
This video we are going to discuss entity integrity. As a review, what is integrity? When we say integrity we are talking about data integrity. Data integrity is a thing we strive for when we are building a database. It essentially means that our data is correct, as up to date as possible, not conflicting with others, and our database design is optimized to protect this.
There are three categories of data integrity. The first type is known as entity integrity.
Before we dive into integrity though, you should first understand our goal when storing data. We always try to focus on singularity and avoid plurality. This concept is known as the rule of one.
When we create a table, we design it to store information about one kind of entity. So for example, we could have a table for cars at a car dealership. Now, we are using the word cars plural, but the concept of cars describes one type of thing. This is known as the entity type. They entity type should be of one type of thing.
This is just one example of where we try to make things singular. You will see many more as we go through these integrity concepts.
Entity integrity refers to the concept of the primary key. Specifically that the primary key should be UNIQUE, and NOT NULL.
Imagine having two rows with the exact same data. Is it a duplicate, or two cars with the same information? This is a problem. The primary key is there to protect us from this. If we give some column that is unique to every row, then we will know that these describe two different entities.
We often use surrogate keys. These are computer generated numbers just for the purpose of protecting our entity integrity. Some people use natural keys instead. A natural key is a key that uses something from the real world to force uniqueness. For example, we can give every use a username on a website to force uniqueness.
I think it is good practice to be familiar with both surrogate and natural keys, but I think the majority of people use surrogate keys.
In addition to the primary key being UNIQUE, it must also be NOT NULL. That means every entity has a value for the primary key.
Your primary key also should never change. Think about it…if an ID of 7 points to a specific entity, and then the ID changes to 10…Are we talking about the same entity with a new ID, or a new entity altogether?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support me! http://www.patreon.com/calebcurry
Subscribe to my newsletter: http://bit.ly/JoinCCNewsletter
Donate!: http://bit.ly/DonateCTVM2.
~~~~~~~~~~~~~~~Additional Links~~~~~~~~~~~~~~~
More content: http://CalebCurry.com
Facebook: http://www.facebook.com/CalebTheVideoMaker
Google+: https://plus.google.com/+CalebTheVideoMaker2
Twitter: http://twitter.com/calebCurry
Amazing Web Hosting - http://bit.ly/ccbluehost (The best web hosting for a cheap price!)
-
MySQL 1 - Intro to MySQL
MySQL 2 - Installing MySQL
MySQL 3 - MySQL Workbench
MySQL 4 - Beginner Terms Part 1
MySQL 5 - Beginner Terms Part 2
MySQL 6 - Beginner Terms Part 3
MySQL 7 - One-to-One Relationship
MySQL 8 - One-to-Many Relationship
MySQL 9 - Many-to-Many Relationship
MySQL 10 - Summary of Relationships
MySQL 11 - Entity Integrity
MySQL 12 - Referential Integrity
MySQL 13 - Domain Integrity
MySQL 14 - Primary Key
MySQL 15 - Auto Increment (AUTO_INCREMENT)
MySQL 16 - Foreign Key
MySQL 17 - ON DELETE and ON UPDATE
MySQL 18 - Intro to Normalization
MySQL 19 - 1NF
MySQL 20 - 2NF
MySQL 21 - 3NF
MySQL 22 - Normalization Summary
MySQL 23 - Intro to Data Types
MySQL 24 - Important Data Types
MySQL 25 - CHAR Data Type
MySQL 26 - VARCHAR Data Type
MySQL 27 - TEXT, TINYTEXT, MEDIUMTEXT, LONGTEXT
MySQL 28 - ENUM
MySQL 29 - SET Data Type
MySQL 30 - INT Data Type
MySQL 31 - DECIMAL Data Type
MySQL 32 - FLOAT and DOUBLE Data Types
MySQL 33 - Datetime, Date, Time Data Types
MySQL All-in-One Quick Concepts Tutorial Series (3 HOURS!)