O'Reilly logo

Beginning Microsoft® SQL Server® 2012 Programming by Paul Atkinson, Robert Vieira

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 5

Creating and Altering Tables

WHAT YOU WILL LEARN IN THIS CHAPTER:

  • SQL object naming rules and conventions
  • How to create a database using a script
  • How to create a table using a script
  • How to alter and drop objects
  • Ways to create and alter objects using the GUI
  • Script creation through the GUI

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, you’ll study the syntax for creating your own tables. You’ll also take a look at how to make use of the SQL Management Studio to help with this (after you know how to do it for yourself).

However, before you learn too much about the actual statements that create tables and other objects, I need to digress far enough to deal with the convention for a fully qualified object name and, to a lesser extent, object ownership.

OBJECT NAMES IN SQL SERVER

In all the queries that you’ve been performing so far in this book, you’ve ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required