Understanding More About Joins

Now that you have written a join, let's take a moment to understand how joins work.

Listing 5.1 shows the code to create and populate two small tables in an automobile database. The first table is a list of car Makes; that is, manufacturers of automobiles. The second table is a list of Models. Each model corresponds to an entry in the Makes table.

Code Listing 5.1. Create and Populate Small Makes and Models Tables to Practice Joining Tables
 1: create table Makes ( 2: MakeID int identity primary key, 3: MakeDescription nvarchar(10) not null 4: ) 5: go 6: create table Models ( 7: ModelID int identity (101,1) primary key, 8: MakeID int not null references Makes (MakeID), 9: ModelName nvarchar(20) not null 10: ) 11: ...

Get Sams Teach Yourself Transact-SQL in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.