Every time I teach the T-SQL code for creating databases, tables, keys, and constraints, I am asked the same question, "Can't you just do this in the GUI tool?" The answer is an unequivocal "Yes!" Therefore, the next question usually follows quite shortly behind, "Then why are we spending all this time learning stuff I'll never use?" The answer is just as unequivocal—you will use the regular syntax on a quasi-regular basis. The reality is you probably won't actually write the code from scratch that often, but you'll verify and edit it on the majority of all larger database projects you work on—that means that you had better know how it works.
In this chapter, we will be studying the syntax for creating your own tables. We will also take a look at how to make use of the SQL Management Studio to help us with this (after we know how to do it for ourselves).
However, before we get too deep in the actual statements that create tables and other objects, we need to digress far enough to deal with the convention for a fully qualified object name, and, to a lesser extent, object ownership.
In all the queries that we've been performing so far in this book, you've seen simple naming at work. I've had you switch the active database in the Query Analyzer before running any queries and that has helped your queries to work. How? Well, SQL Server looks at only a very narrow scope when trying to identify and locate the objects you name ...