Previous Page
Next Page

11.1. The "Simple" CREATE TABLE

You have seen a "simple" CREATE TABLE statement in Chapter 3. To refresh your memory, here is an example:

CREATE TABLE Test1
  (name            VARCHAR(20),
   ssn             CHAR(9),
   dept_number     INT,
   acct_balance    SMALLMONEY)

The following are the elements of this CREATE TABLE command:

  • We created a table called Test1.

  • name is a variable-length character string with maximum length of 20

  • ssn (Social Security number) is a fixed-length character string of length 9

  • dept_number is an integer (which in SQL Server simply means no decimals allowed)

  • acct_balance is a currency column

Beyond choosing data types for columns in tables, you may need to make other choices to create an effective database. You can create indexes on tables, which then can be used to aid in the enforcement of certain validation rules. You also can use other "add-ons" called CONSTRAINTs, which make you enter good data (or, prevents you from entering invalid data into the database) and hence maintain the integrity of a database. In the following sections, we explore indexes and then CONSTRAINTs.


Previous Page
Next Page