1.3. SQL Server Data Types
Now that you're familiar with the base objects of a SQL Server database, let's take a look at the options that SQL Server has for one of the fundamental items of any environment thathandles data: data types. Note that since this book is intended for developers and that no developer could survive for 60 seconds without an understanding of data types, I'm going to assume that you already know how data types work and just need to know the particulars of SQL Server data types.
SQL Server 2005 has the intrinsic data types shown in the following table:
Data Type Name | Class | Size in Bytes | Nature of the Data |
---|---|---|---|
Bit | Integer | 1 | The size is somewhat misleading. The first bit data type in a table takes up one byte; the next seven make use of the same byte. Allowing nulls causes an additional byte to be used. |
Bigint | Integer | 8 | This just deals with the fact that we use larger and larger numbers on a more frequent basis. This one allows you to use whole numbers from −263 to 263−1. That's plus or minus about 92 quintrillion. |
Int | Integer | 4 | Whole numbers from −2,147,483,648 to 2,147,483,647. |
SmallInt | Integer | 2 | Whole numbers from −32,768 to 32,767. |
TinyInt | Integer | 1 | Whole numbers from 0 to 255. |
Decimal or Numeric | Decimal/Numeric | Varies | Fixed precision and scale from −1038−1 to 1038−1. The two names are synonymous. |
Money | Money | 8 | Monetary units from −263 to 263 plus precision to four decimal places. Note that this could be any monetary unit, not just dollars. |
SmallMoney | Money | 4 | Monetary units from −214,748.3648 ... |
Get Professional SQL Server™ 2005 Programming 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.