数据类型同义词 (Transact-SQL)Data type synonyms (Transact-SQL)

适用对象:yesSQL Server(从 2012 版开始)noAzure SQL 数据库noAzure SQL 数据仓库no并行数据仓库APPLIES TO: yesSQL Server (starting with 2012) noAzure SQL Database noAzure SQL Data Warehouse 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 )] for n = 1-7float[(n)] for n = 1-7 realreal
float[( n )] for 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 *@variable*。These 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)