How Transact-SQL datatypes work

In Transact-SQL, datatypes specify the type of information, size, and storage format of table columns, stored procedure parameters, and local variables. For example, the int (integer) datatype stores whole numbers in the range of plus or minus 231, and the tinyint (tiny integer) datatype stores whole numbers between 0 and 255 only.

Adaptive Server supplies several system datatypes, and two user-defined datatypes, timestamp and sysname. Use sp_addtype to build user-defined datatypes based on the system datatypes.

You must specify a system datatype or user-defined datatype when declaring a column, local variable, or parameter. The following example uses the system datatypes char, numeric, and money to define the columns in the create table statement:

create table sales_daily
    (stor_id char(4),
    ord_num numeric(10,0),
    ord_amt money)

The next example uses the bit system datatype to define the local variable in the declare statement:

declare @switch bit

Subsequent chapters describe in more detail how to declare columns, local variables, and parameters using the datatypes described in this chapter. Use sp_help to determine which datatypes have been defined for columns of existing tables.