1.4. SQL Server Identifiers for Objects

Now you've heard all sorts of things about objects in SQL Server. But let's take a closer look at naming objects in SQL Server.

1.4.1. What Gets Named?

Basically, everything has a name in SQL Server. Here's a partial list:

Stored proceduresTablesColumns
ViewsRulesConstraints
DefaultsIndexesFilegroups
TriggersDatabasesServers
User-defined functionsLoginsRoles
Full-text catalogsFilesUser-defined types
Schemas  

And the list goes on. Most things I can think of except rows (which aren't really objects) have a name. The trick is to make every name both useful and practical.

1.4.2. Rules for Naming

The rules for naming in SQL Server are fairly relaxed, allowing things like embedded spaces and even keywords in names. Like most freedoms, however, it's easy to make some bad choices and get yourself into trouble.

Here are the main rules:

  • The name of your object must start with any letter as defined by the specification for Unicode 2.0. This includes the letters most westerners are used to — A-Z and a-z. Whether "A" is different from "a" depends on the way your server is configured, but eithermakes for a valid beginning to an object name. After that first letter, you're pretty much free to run wild; almost any character will do.

  • The name can be up to 128 characters for normal objects and 116 for temporary objects.

  • Any names that are the same as SQL Server keywords or contain embedded spaces must be enclosed in double quotes ("") or square brackets ([]). ...

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.