From the course: SQL Server 2008 Essential Training
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Defining keys - SQL Server Tutorial
From the course: SQL Server 2008 Essential Training
Defining keys
One thing you should do on all of your tables, at least as a general rule, is defined what's called a primary key. This is a way that's going to identify how do we get to an individual role. One value that would always take us to just one row in that table. And your primary key can be any of the columns that you actually have defined if that makes sense. Sometimes it does, sometimes it doesn't. If I look at my Product Table, for example I have ProductID, ProductName, UnitPrice and UnitsInStock, and let's say that my business process was such that ProductIDs were decided around a conference table and manually entered into the database. Well I could say then ProductID should be my primary key. One ProductID should always identify a row in this table in this database. Well I have it open in Design. I can right- click the column and just say Set primary key. Notice what happens to the Allow Nulls column when I do this. It's going to turn it off because when you think about it, it doesn't…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
Planning your database9m 39s
-
(Locked)
Creating a SQL Server database4m 7s
-
(Locked)
Creating tables7m 50s
-
Data types in SQL Server12m 25s
-
(Locked)
Defining keys8m 9s
-
(Locked)
Creating default values4m 39s
-
(Locked)
Creating check constraints2m 25s
-
(Locked)
Creating unique constraints4m 34s
-
Introduction to relationships and foreign keys9m 51s
-
(Locked)
Creating relationships in SQL Server Management Studio8m 14s
-
(Locked)
Database normalization11m 47s
-
(Locked)
Creating computed columns3m 10s
-
-
-
-
-
-
-
-
-
-
-
-