Locked lesson.
About this lesson
We will discuss the Primary Key and why it's so important
Exercise files
Download this lesson’s related exercise files.
Primary Key.docx59.2 KB Primary Key - Solution.docx
59.6 KB
Quick reference
Primary Key
A Primary Key creates a unique ID for each record in a table.
When to use
You should always designate a primary key for your tables.
Instructions
To create a new table with a Primary Key that auto generates every time a new record is added:
CREATE TABLE Persons (
ID int IDENTITY(1,1) PRIMARY KEY,
FirstName varchar(50),
LastName varchar(50)
)
Hints & tips
- Primary Keys create a unique ID for each record in a table.
- Always use Primary Keys!
Lesson notes are only available for subscribers.