bit (Transact-SQL)bit (Transact-SQL)

適用於: 是SQL Server 是Azure SQL Database 是Azure Synapse Analytics (SQL DW) 是平行處理資料倉儲 APPLIES TO: yesSQL Server yesAzure SQL Database yesAzure Synapse Analytics (SQL DW) yesParallel Data Warehouse

一種整數資料類型,其值有 1、0 或 NULL 幾種。An integer data type that can take a value of 1, 0, or NULL.

RemarksRemarks

SQL Server Database EngineSQL Server Database Engine 可將 bit 資料行的儲存體最佳化。The SQL Server Database EngineSQL Server Database Engine optimizes storage of bit columns. 如果資料表中的 bit 資料行小於或等於 8 個,這些資料行會儲存為 1 個位元組。If there are 8 or fewer bit columns in a table, the columns are stored as 1 byte. 如果有 9 到 16 個 bit 資料行,則儲存為 2 個位元組,依此類推。If there are from 9 up to 16 bit columns, the columns are stored as 2 bytes, and so on.

字串值 TRUE 和 FALSE 可以轉換成 bit 值:TRUE 會轉換成 1,FALSE 則轉換成 0。The string values TRUE and FALSE can be converted to bit values: TRUE is converted to 1 and FALSE is converted to 0.

轉換成位元會將任何非零的值升級成 1。Converting to bit promotes any nonzero value to 1.

另請參閱See also

ALTER TABLE (Transact-SQL)ALTER TABLE (Transact-SQL)
CAST 和 CONVERT (Transact-SQL)CAST and CONVERT (Transact-SQL)
CREATE TABLE (Transact-SQL)CREATE TABLE (Transact-SQL)
資料類型轉換 (資料庫引擎)Data Type Conversion (Database Engine)
資料類型 (Transact-SQL)Data Types (Transact-SQL)
DECLARE @local_variable (Transact-SQL)DECLARE @local_variable (Transact-SQL)
SET @local_variable (Transact-SQL)SET @local_variable (Transact-SQL)
sys.types (Transact-SQL)sys.types (Transact-SQL)