PARSENAME (Transact-SQL)PARSENAME (Transact-SQL)

适用于:Applies to: 是SQL ServerSQL Server(所有支持的版本)yesSQL ServerSQL Server (all supported versions) 是Azure SQL 数据库Azure SQL DatabaseYesAzure SQL 数据库Azure SQL Database 是Azure SQL 托管实例Azure SQL Managed InstanceYesAzure SQL 托管实例Azure SQL Managed Instance 是Azure Synapse AnalyticsAzure Synapse AnalyticsyesAzure Synapse AnalyticsAzure Synapse Analytics 是并行数据仓库Parallel Data Warehouseyes并行数据仓库Parallel Data Warehouse适用于:Applies to: 是SQL ServerSQL Server(所有支持的版本)yesSQL ServerSQL Server (all supported versions) 是Azure SQL 数据库Azure SQL DatabaseYesAzure SQL 数据库Azure SQL Database 是Azure SQL 托管实例Azure SQL Managed InstanceYesAzure SQL 托管实例Azure SQL Managed Instance 是Azure Synapse AnalyticsAzure Synapse AnalyticsyesAzure Synapse AnalyticsAzure Synapse Analytics 是并行数据仓库Parallel Data Warehouseyes并行数据仓库Parallel Data Warehouse

返回对象名称的指定部分。Returns the specified part of an object name. 可检索的对象部分包括对象名称、架构名称、数据库名称和服务器名称。The parts of an object that can be retrieved are the object name, schema name, database name, and server name.

备注

PARSENAME 函数不指示指定名称的对象是否存在。The PARSENAME function does not indicate whether an object by the specified name exists. PARSENAME 仅返回指定对象名称的指定部分。PARSENAME just returns the specified part of the specified object name.

主题链接图标 Transact-SQL 语法约定Topic link icon Transact-SQL Syntax Conventions

语法Syntax

PARSENAME ('object_name' , object_piece )

备注

若要查看 SQL Server 2014 及更早版本的 Transact-SQL 语法,请参阅早期版本文档To view Transact-SQL syntax for SQL Server 2014 and earlier, see Previous versions documentation.

参数Arguments

“object_name”参数具有要检索其指定部分的对象的名称。'object_name' Is the parameter that holds the name of the object for which to retrieve the specified object part. 此参数是可选的限定对象名称。This parameter is an optionally-qualified object name. 如果对象名称的所有部分都是限定的,则此名称可包含四部分:服务器名称、数据库名称、架构名称以及对象名称。If all parts of the object name are qualified, this name can have four parts: the server name, the database name, the schema name, and the object name. “object_name”字符串的每个部分都是 sysname 类型,它等效于 nvarchar(128) 或 256 个字节。Each part of the 'object_name' string is type sysname which is equivalent to nvarchar(128) or 256 bytes. 如果字符串的任何部分超过 256 个字节,PARSENAME 将对该部分返回 NULL,因为它不是有效的 sysname。If any part of the string exceeds 256 bytes, PARSENAME will return NULL for that part as it is not a valid sysname.

object_pieceobject_piece
要返回的对象部分。Is the object part to return. object_piece 的数据类型为 int,可以为下列值:object_piece is of type int, and can have these values:
1 = 对象名称1 = Object name
2 = 架构名称2 = Schema name
3 = 数据库名称3 = Database name
4 = 服务器名称4 = Server name

返回类型Return Type

sysnamesysname

备注Remarks

如果存在下列条件之一,则 PARSENAME 返回 NULL:PARSENAME returns NULL if one of the following conditions is true:

  • object_name 或 object_piece 为 NULL 。Either object_name or object_piece is NULL.

  • 发生语法错误。A syntax error occurs.

请求的对象部分长度为 0,且不是有效的 MicrosoftMicrosoft SQL ServerSQL Server 标识符。The requested object part has a length of 0 and is not a valid MicrosoftMicrosoft SQL ServerSQL Server identifier. 长度为零的对象的名称将使整个限定名称无效。A zero-length object name renders the complete qualified name as not valid.

示例Examples

以下示例使用 PARSENAME 返回有关 Person 数据库中 AdventureWorks2012 表的信息。The following example uses PARSENAME to return information about the Person table in the AdventureWorks2012 database.

-- Uses AdventureWorks  
  
SELECT PARSENAME('AdventureWorksPDW2012.dbo.DimCustomer', 1) AS 'Object Name';  
SELECT PARSENAME('AdventureWorksPDW2012.dbo.DimCustomer', 2) AS 'Schema Name';  
SELECT PARSENAME('AdventureWorksPDW2012.dbo.DimCustomer', 3) AS 'Database Name';  
SELECT PARSENAME('AdventureWorksPDW2012.dbo.DimCustomer', 4) AS 'Server Name';  
GO  

下面是结果集:Here is the result set.

Object Name
------------------------------
DimCustomer

(1 row(s) affected)

Schema Name
------------------------------
dbo

(1 row(s) affected)

Database Name
------------------------------
AdventureWorksPDW2012

(1 row(s) affected)

Server Name
------------------------------
(null)

(1 row(s) affected)

另请参阅See Also