Appendix A. Command Syntax Reference

SQL Server 2005 and SQL Server 2008 recognize up to four parts of object names. Depending on the context of an expression, some parts may or may not be necessary when referencing an object. When a script runs on a different server or when you are using a different database, related object names may be required. Note that both SQL Server 2005 and SQL Server 2008 recognize the schema name in the third position, whereas SQL Server 2000 and earlier versions recognized the object owner name in the third position. The following table summarizes valid syntax for referencing database objects.

Object Reference

Use and Context

object

Used in the context of the local database, on the same server. Object is part of the dbo schema and there are no duplicate object names.

schema.object

Used in the context of the local database, on the same server. Duplicate object names that have schema names (and subsequently, different owners) are permitted. Also uses a standard convention for clarity.

database..object

Used in the context of the same or different database on the same server. If you haven't specified the owner or schema, assumes the dbo schema.

database.schema.object

A three-part name fully describes an object on the same server, in the same or different database.

server.database.schema.object

A four-part name is valid in the context of a remote server or the local server, in the local or a different database, and for any schema.

server.database..object

The database owner ...

Get Beginning T-SQL with Microsoft® SQL Server® 2005 and 2008 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.