Data Types

One of the steps in designing a database is to declare the type of each field. This declaration enables the database engine to save and retrieve data efficiently. SQL Server provides 21 different types of data. Table 1.1 lists the data types available to you in a database application.

Table 1.1. Data Types Available in SQL Server

Data Type

Description

bigint

An eight-byte integer (whole number) in the range of 9,223,372,036,854,775,808 through 9,223,372,036,854,775,807.

binary

Used to store fixed-length binary data of up to 8,000 bytes.

boolean

A true or false value stored as 0 or 1.

char

A fixed-length character field of up to 8,000 characters.

datetime

A value that can store a date and time value between January 1, 1753, and December 31, 9999.

decimal

Fixed-precision decimal numbers. You can define the scale (number of digits to the right of the decimal point) when you create the field. Data in a decimal field takes 5 to 17 bytes of storage.

float

Approximate decimal number with up to 53 digits to the right of the decimal. It requires either four or eight bytes of storage, depending on the scale of the number.

image

Variable-length binary data of up to 2,147,483,647 bytes.

int

A four-byte whole number from 2,147,483,648 to 2,147,483,647.

money

A numeric field that has special properties to store monetary values accurately.

nchar

A fixed-length character field containing up to 4,000 international (Unicode) characters.

ntext

A variable-length character field containing up to 1,073,741,823 international characters.

nvarchar

A variable-length character field containing up to 4,000 international characters.

real

Approximate decimal number with up to 53 digits to the right of the decimal. Requires either four or eight bytes of storage, depending on the scale of the number.

smalldatetime

A value that can store a date and time value from January 1, 1900, to June 6, 2079.

smallint

A two-byte whole number between 32,768 and 32,767.

text

A variable-length field containing up to 2,147,483,647 characters. (This kind of field is known in some database systems, such as Microsoft Access, as a Memo field.)

tinyint

A single-byte whole number between 0 and 255.

uniqueidentifier

A 128-byte number, also called a globally unique identifier. You can use this number to identify a record uniquely; it is typically used in replication.

varbinary

Variable-length binary data of up to 8,000 bytes.

varchar

A variable-length field containing up to 8,000 characters.

There isn't a one-to-one correspondence between VB.NET's data types and database field data types, although the correspondence is closer in VB.NET than it was in VB6. For example, a SQL Server int data type corresponds to a .NET integer data type; both are 32-bit integers. However, you can't directly set a database field to a user-defined type or a Visual Basic-style Object variable.



Database Access with Visual Basic. NET
Database Access with Visual Basic .NET (3rd Edition)
ISBN: 0672323435
EAN: 2147483647
Year: 2003
Pages: 97

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net