PARSENAME (T-SQL)

Returns the specified part of an object name. Parts of an object that can be retrieved are the object name, owner name, database name, and server name.


Note The PARSENAME function does not indicate whether or not an object by the specified name exists. It just returns the specified piece of the given object name.


Syntax

PARSENAME('object_name ', object_piece)

Arguments
'object_name'
Is the name of the object for which to retrieve the specified object part. object_name is sysname. This parameter is an optionally qualified object name. If all parts of the object name are qualified, this name can consist of four parts: the server name, the database name, the owner name, and the object name.
object_piece
Is the object part to return. object_piece is int, and can have these values.

 

Value Description
1 Object name
2 Owner name
3 Database name
4 Server name

Return Types

nchar

Remarks

PARSENAME returns NULL if any of the following conditions are met:

Examples

This example uses PARSENAME to return information about the authors table in the pubs database.

USE pubs

SELECT PARSENAME('pubs..authors', 1) AS 'Object Name'

SELECT PARSENAME('pubs..authors', 2) AS 'Owner Name'

SELECT PARSENAME('pubs..authors', 3) AS 'Database Name'

SELECT PARSENAME('pubs..authors', 4) AS 'Server Name'

  

Here is the result set:

Object Name                   

------------------------------

authors                       

  

(1 row(s) affected)

  

Owner Name                    

------------------------------

(null)                        

  

(1 row(s) affected)

  

Database Name                 

------------------------------

pubs                          

  

(1 row(s) affected)

  

Server Name                   

------------------------------

(null)                        

  

(1 row(s) affected)

  

See Also
ALTER TABLE System Functions
CREATE TABLE  

  


(c) 1988-98 Microsoft Corporation. All Rights Reserved.