# int、bigint、smallint 和 tinyint (Transact-SQL)int, bigint, smallint, and tinyint (Transact-SQL)

bigintbigint -2^63 (-9,223,372,036,854,775,808) 到 2^63-1 (9,223,372,036,854,775,807)-2^63 (-9,223,372,036,854,775,808) to 2^63-1 (9,223,372,036,854,775,807) 8 個位元組8 Bytes
intint -2^31 (-2,147,483,648) 到 2^31-1 (2,147,483,647)-2^31 (-2,147,483,648) to 2^31-1 (2,147,483,647) 4 個位元組4 Bytes
smallintsmallint -2^15 (-32,768) 到 2^15-1 (32,767)-2^15 (-32,768) to 2^15-1 (32,767) 2 位元組2 Bytes
tinyinttinyint 0 至 2550 to 255 1 位元組1 Byte

## RemarksRemarks

int 資料類型是 SQL ServerSQL Server 中的主要整數資料類型。The int data type is the primary integer data type in SQL ServerSQL Server. bigint 資料類型通常是在整數值可能超過 int 資料類型所支援的範圍時使用。The bigint data type is intended for use when integer values might exceed the range that is supported by the int data type.

bigint 位於資料類型優先順序圖表中 smallmoneyint 之間。bigint fits between smallmoney and int in the data type precedence chart.

## 轉換整數資料Converting integer data

``````SELECT 2147483647 / 2 AS Result1, 2147483649 / 2 AS Result2 ;
``````

``````Result1      Result2
1073741823   1073741824.500000
``````

## 範例Examples

``````CREATE TABLE dbo.MyTable
(
MyBigIntColumn bigint
,MyIntColumn  int
,MySmallIntColumn smallint
,MyTinyIntColumn tinyint
);

GO

INSERT INTO dbo.MyTable VALUES (9223372036854775807, 2147483647,32767,255);
GO
SELECT MyBigIntColumn, MyIntColumn, MySmallIntColumn, MyTinyIntColumn
FROM dbo.MyTable;
``````

``````MyBigIntColumn       MyIntColumn MySmallIntColumn MyTinyIntColumn
-------------------- ----------- ---------------- ---------------
9223372036854775807  2147483647  32767            255

(1 row(s) affected)
``````