SQL Clone
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

The parts of an object’s name

Any object within a database in SQL Server has what is called a four part name. Which rather implies four pieces right? Simple enough


And you can find the lists of each of those pieces in

The breakdown is nice but how about usage? Let’s use an object in AdventureWorks2014 as an example.

One Part Name
This is just the name of the object. This is probably the most common usage and yet the only one I would recommend never using. (I’ll freely admit I’m not great at this myself btw.) When you only use a single name the schema is implied by the default schema of the user running the statement. That means that the same statement run by two different users could have two different meanings. Since most users have a default schema of dbo this would probably hit the object dbo.vIndividualCustomer. Assuming one even existed.

Two Part Name
This is the name of the object and the name of the schema. It specifically identifies an object within the database and for the reason stated above is what you should be using in most cases.

Three Part Name
Now we add the name of the database. You only really need this one if you are doing cross database queries or aren’t sure what context your query will be running under. In other words, if you are creating a script for someone else to use, and you aren’t sure if they are going to run it from master, or some userDB or even tempdb, then you had best use a three part name to call all of your objects. And if you are writing a query that references objects from two (or more) different databases at once (master and msdb for example) then you have to use a three part name for at least some of the objects (some, of course, can be from the current database).

Four Part Name
Last but not least we add on the instance name. You’ll only need/see this if you are referencing an instance other than the one you are on. The most common (and only??) way being a linked server. You could use this in place of any of one, two, or three part names but there is really no point and most people don’t because of the extra typing.

Some bonus knowledge. There is a great function called parsename that splits the name up by position.

PRINT parsename('(local)\sql2016cs.AdventureWorks2014.Sales.vIndividualCustomer'
PRINT parsename('(local)\sql2016cs.AdventureWorks2014.Sales.vIndividualCustomer'
PRINT parsename('(local)\sql2016cs.AdventureWorks2014.Sales.vIndividualCustomer'
PRINT parsename('(local)\sql2016cs.AdventureWorks2014.Sales.vIndividualCustomer'

Filed under: Microsoft SQL Server, SQLServerPedia Syndication, T-SQL Tagged: microsoft sql server, T-SQL


My name is Kenneth Fisher and I am Senior DBA for a large (multi-national) insurance company. I have been working with databases for over 20 years starting with Clarion and Foxpro. I’ve been working with SQL Server for 12 years but have only really started “studying” the subject for the last 3. I don’t have any real "specialities" but I enjoy trouble shooting and teaching. Thus far I’ve earned by MCITP Database Administrator 2008, MCTS Database Administrator 2005, and MCTS Database Developer 2008. I’m currently studying for my MCITP Database Developer 2008 and should start in on the 2012 exams next year. My blog is at www.sqlstudies.com.


Leave a comment on the original post [sqlstudies.com, opens in a new window]

Loading comments...