資料類型同義字 (Transact-SQL)Data type synonyms (Transact-SQL)

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

SQL ServerSQL Server 包括資料類型同義字,是為了與 ISO 相容。Data type synonyms are included in SQL ServerSQL Server for ISO compatibility. 下表列出同義字和它們所對應的 SQL ServerSQL Server 系統資料類型。The following table lists the synonyms and the SQL ServerSQL Server system data types that they map to.

同義字Synonym SQL Server 系統資料類型SQL Server system data type
Binary varyingBinary varying varbinaryvarbinary
char varyingchar varying varcharvarchar
charactercharacter charchar
charactercharacter char(1)char(1)
character( n )character(n) char(n)char(n)
character varying( n )character varying(n) varchar(n)varchar(n)
DecDec decimaldecimal
Double precisionDouble precision floatfloat
float[ ( n ) ] 適用於 n = 1-7float[(n)] for n = 1-7 realreal
float[ ( n ) ] 適用於 n = 8-15float[(n)] for n = 8-15 floatfloat
integerinteger intint
national character( n )national character(n) nchar(n)nchar(n)
national char( n )national char(n) nchar(n)nchar(n)
national character varying( n )national character varying(n) nvarchar(n)nvarchar(n)
national char varying( n )national char varying(n) nvarchar(n)nvarchar(n)
national textnational text ntextntext
timestamptimestamp rowversionrowversion

資料類型同義字可用來取代資料定義語言 (DDL) 陳述式中對應的基底資料類型名稱。Data type synonyms can be used instead of the corresponding base data type name in data definition language (DDL) statements. 這些陳述式包括 CREATE TABLE、CREATE PROCEDURE 和 DECLARE @variableThese statements include CREATE TABLE, CREATE PROCEDURE, and DECLARE @variable. 不過,建立好物件之後,就看不見同義字了。However, after the object is created, the synonyms have no visibility. 當建立物件時,會將同義字的相關基底資料類型指派給物件。When the object is created, the object is assigned the base data type that is associated with the synonym. 沒有在建立物件的陳述式中指定同義字的記錄。There's no record that the synonym was specified in the statement that created the object.

從原始物件衍生的物件 (例如結果集資料行或運算式) 都會被指派基底資料類型。Objects that are derived from the original object, such as result set columns or expressions, are assigned the base data type. 使用原始物件或任何衍生物件的所有中繼資料函數都將報告基底資料類型,而非同義字,包括:Any metadata functions that use the original object or any derived objects will report the base data type, not the synonym, including:

  • 中繼資料作業 (例如sp_help 和其他系統預存程序),Metadata operations, such as sp_help and other system stored procedures,
  • 資訊結構描述檢視,以及Information schema views, and
  • 資料存取 API 中繼資料作業,可用來報告資料類型的資料表或結果集資料行。Data access API metadata operations that report the data types of table or result set columns.

例如,您可以指定 national character varying 來建立一份資料表:For example, you can create a table by specifying national character varying:

CREATE TABLE ExampleTable (PriKey int PRIMARY KEY, VarCharCol national character varying(10))  

VarCharCol 會被指派 nvarchar(10) 資料類型,而所有後續的中繼資料函數都會將資料行報告成 nvarchar(10) 資料行。VarCharCol is assigned an nvarchar(10) data type, and all following metadata functions will report the column as an nvarchar(10) column. 中繼資料函式永遠不會將它們報告成 national character varying(10) 資料行。The metadata functions will never report them as a national character varying(10) column.

另請參閱See also

資料類型 (Transact-SQL)Data Types (Transact-SQL)