## SQLWays - Sybase Data Types

This chapter describes the data types supported by Sybase.

- char, nchar, varchar and nvarchar
- int, smallint and tinyint
- datetime and smalldatetime
- money and smallmoney
- decimal and numeric
- float, double precision and real
- text
- binary, varbinary and image
- bit and timestamp

### char, nchar, varchar and nvarchar

char[(n)]

Fixed-length character data in single-byte character sets with length of n characters. n must be a value from 1 through 255. Storage size is n bytes.

nchar[(n)]

Fixed-length character data in multibyte character sets with length of n characters. n must be a value from 1 through 255. Storage size is n*@@ncharsize bytes.

varchar[(n)]

Variable-length character data in single-byte character sets with length of n characters. n must be a value from 1 through 255. Storage size is the actual length of the data entered, not n bytes.

nvarchar[(n)]

Variable-length character data in multibyte character sets with length of n characters. n must be a value from 1 through 255. Storage size, in bytes, is the actual number of characters entered * @@ncharsize.

Remarks

When n is not specified in a data definition, the default length is 1.

### int, smallint and tinyint

int

Integer (whole number) data from -2^31 (-2,147,483,648) through 2^31 - 1 (2,147,483,647). Storage size is 4 bytes.

smallint

Integer (whole number) data from -2^15 (-32,768) through 2^15 - 1 (32,767). Storage size is 2 bytes.

tinyint

Integer (whole number) data from 0 through 255. Storage size is 1 byte.

### datetime and smalldatetime

Date and time data types for representing date and time of day.

datetime

Date and time data from January 1, 1753, through December 31, 9999, with an accuracy of 1/300 of a second, or 3.33 milliseconds. Storage size is 8 bytes.

smalldatetime

Date and time data from January 1, 1900, through June 6, 2079, with an accuracy of one minute. Storage size is 4 bytes.

### money and smallmoney

Monetary data types for representing monetary or currency values.

money

Monetary data values from -2^63 (-922,337,203,685,477.5808) through 2^63 - 1 (+922,337,203,685,477.5807), with accuracy to a ten-thousandth of a monetary unit. Storage size is 8 bytes.

smallmoney

Monetary data values from - 214,748.3648 through +214,748.3647, with accuracy to a ten-thousandth of a monetary unit. Storage size is 4 bytes.

### decimal and numeric

Numeric data types with fixed precision and scale.

decimal[(p[,s])]

Fixed precision and scale numbers. When maximum precision is used, valid values are from - 10^38 +1 through 10^38 - 1.

p (precision) specifies the maximum total number of decimal digits that can be stored, both to the left and to the right of the decimal point. The precision must be a value from 1 through the maximum precision. The maximum precision is 38. The default precision is 18 digits.

s (scale) specifies the maximum number of decimal digits that can be stored to the right of the decimal point. Scale must be a value from 0 through p. The default scale is 0; therefore, 0 <= s <= p. Maximum storage sizes vary, based on the precision.

numeric[(p[,s])]

The numeric and decimal datatypes are identical in all respects but one: only numeric datatypes with a scale of 0 can be used for the IDENTITY column.

### float, double precision and real

Approximate number data types for use with floating point numeric data. Floating point data is approximate; not all values in the data type range can be precisely represented.

float[(precision)]

Floating point number. Storage size is 4 bytes if precision < 16, and 8 bytes if precision >= 16. The range and storage precision is machine dependent.

float columns with a precision of 1-15 are stored as real; those with higher precision are stored as double precision.

double precision

Floating point number. Storage size is 8 bytes. The range and storage precision is machine dependent.

real

Floating point number. Storage size is 4 bytes. The range and storage precision is machine dependent.

### text

Variable-length character strings.

text

Variable-length character data with a maximum length of 2^31 - 1 (2,147,483,647) characters.

### binary, varbinary and image

Binary data types.

binary[(n)]

Fixed-length binary data of n bytes. n must be a value from 1 through 255. When n is not specified, the default length is 1.

varbinary[(n)]

Variable-length binary data of n bytes. n must be a value from 1 through 255. When n is not specified, the default length is 1.

image

Variable-length binary data from 0 through 2^31-1 (2,147,483,647) bytes.

### bit and timestamp

bit

Integer data type that can be 1 or 0. Integer values other than 0 or 1 are accepted, but are always interpreted as 1. Columns with a datatype of bit cannot be NULL.

timestamp

Datatype that is defined as varbinary(8). It requires 8 bytes of storage.

Sybase updates the timestamp column each time its row is modified. A table can have only one column of timestamp datatype.

[Main] [Table of Contents]
Copyright © 1999-2003 Ispirer Systems. All Rights Reserved.
SQLWays™ www.ispirer.com.