Creating Tables Using T-SQL

This section examines how to use T-SQL to create tables. You will see how to define table columns and set properties for the columns. Also covered is defining a location for the table, adding constraints, and making modifications to existing tables.

Defining Columns

In defining a column, you assign a name and a datatype to the column. Depending on the datatype you choose, you might also have to assign parameters to the datatype, such as a length for a char() column. Listing 12.3 shows a simple CREATE TABLE statement defining six columns.

Listing 12.3. Defining Columns with CREATE TABLE
CREATE TABLE yourdb.dbo.employee
(
  Emp_no int,
  Lname varchar(20),
  Fname varchar(20),
  Phone char(13),
  Dept smallint,
  Salary money

Get Microsoft® SQL Server™ 2000 Unleashed, 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.