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.
PARSENAME('object_name ', object_piece)
Value | Description |
---|---|
1 | Object name |
2 | Owner name |
3 | Database name |
4 | Server name |
nchar
PARSENAME returns NULL if any of the following conditions are met:
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)
ALTER TABLE | System Functions |
CREATE TABLE |