From the course: Microsoft SQL Server 2022 Essential Training
Unlock this course with a free trial
Join today to access over 24,100 courses taught by industry experts.
Create a foreign key column - SQL Server Tutorial
From the course: Microsoft SQL Server 2022 Essential Training
Create a foreign key column
- [Instructor] To apply the concept of a foreign key column to our Red30 tech database, I want to create a new table. We have a table for customers, and we also have a table for products. So it would make sense if we had a table for orders where we could store information about the products that specific customers have ordered. Let's right click on the table's folder, point to new, and choose table, and that'll start up a new table design window. The first column is going to be the order ID. We'll store this as an int data type, and I do not want to allow nulls, so I'll turn that checkbox off. Then down in the properties, I want to apply the identity specification property so I'll find that and twirl it open. I'll change the is identity property to yes, and I'll leave the seed and increment both set to one. I also want this order ID to be the primary key for the table, so I'll come back up here to the top and click the…
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
-
-
-
-
-
-
Choose appropriate data types2m 46s
-
(Locked)
SQL Server data type options7m 19s
-
(Locked)
Automatically assign record identities4m 54s
-
(Locked)
Primary key fields4m 35s
-
(Locked)
Establish a default value5m 1s
-
(Locked)
Check constraints5m 10s
-
(Locked)
Unique constraints6m 23s
-
(Locked)
Foreign keys4m 16s
-
(Locked)
Create a foreign key column5m 16s
-
(Locked)
Create relationships between tables5m 6s
-
-
-
-
-
-
-