4.1. Object Names in SQL Server

In all the queries that you've been performing so far in this book, you've seen simple naming at work. I've had you switch the active database in the Query Analyzer before running any queries, and that has helped your queries to work. How? Well, SQL Server looks only at a very narrow scope when trying to identify and locate the objects you name in your queries and other statements. For example, you've only been providing the names of tables without any additional information, but there are actually four levels in the naming convention for any SQL Server table (and any other SQL Server object for that matter). A fully qualified name is as follows:

[ServerName.[DatabaseName.[SchemaName.]]]ObjectName

You must provide an object name whenever you are performing an operation on that object, but all parts of the name to the left of the object name are optional. Indeed, most of the time, they are not needed, and are therefore left off. Still, before you start creating objects, it's a good idea for you to get a solid handle on each part of the name. So, now move from the object name left.

4.1.1. Schema Name (a.k.a. Ownership)

If you're utilizing schemas (most older databases do not, but it appears that it will become more important in the future), you may need to indicate what schema your object is in. It is entirely possible to have to objects with the same name, but residing in different schemas. If you're wanting to access an object that is not in your ...

Get Professional SQL Server™ 2005 Programming 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.