Chapter 3. Creating, Populating, Altering, and Deleting Tables

In the SQL Server 2005 database, data is stored in tables (also known as relations in relational database theory). In Chapter 2, we discussed how to write queries to retrieve data from existing tables by using the SELECT statement. In this chapter, we will discuss how to create tables and insert data into them, and how to alter, update, and delete tables and their data using SQL. We start the chapter with a discussion of data types . You need to know the different data types before you can use the CREATE TABLE command to create tables. In the CREATE TABLE command, in addition to the column names, the data types and sizes of the columns have to be included.

Data Types in SQL Server 2005

Every column in a table has a data type. The data type of a column specifies what kind of information or values can be stored in the column, and what kind of operations can be performed on those values. It is a matter of mapping the domain values you need to store to the corresponding data type. In selecting a data type, you should avoid wasting storage space, while allowing enough space for a sufficient range of possible values over the life of your application. SQL Server 2005 supports 30 different data types. We will discuss the most commonly used data types by dividing the data types into four major categories: numeric, character, date and time, and miscellaneous.

Tip

Domain values are the set of all possible values that a column can ...

Get Learning SQL on SQL Server 2005 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.