Using T-SQL to Create Tables

Ultimately, all the tables created with the visual tools can also be created by using T-SQL. As with many of the SSMS tools, database objects can be resolved or scripted into T-SQL statements. Let’s examine the T-SQL syntax to better understand some of the table creation options; then we can discuss the definition of the columns in each table.

The full T-SQL CREATE TABLE syntax is extensive. It includes options to define table constraints, indexes, and index options. SQL Server Books Online shows the full syntax and describes each of these options in detail. Listing 24.1 shows the basic T-SQL syntax; the first part of the syntax is listed in Books Online. This syntax is enough to enable you to create a table with ...

Get Microsoft® SQL Server 2008 R2 Unleashed 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.