Why you shouldn’t qualify your database name

December 21, 2012

When writing SQL queries, there is a performance benefit to be had from qualifying the database schema (e.g. select fooField from dbo.fooTable).

I recently worked on a system where all SQL code was qualified with the database name – e.g. DatabaseName.Schema.TableName.

This in esscence is not a terrible idea – After all, it provides surity that we will always select from the correct database, but,  what happens we we want to rename the database? “I’ll never do that!” No? How about when you have a development copy on a server, and decide you want a second copy on the same server for some reason – Maybe testing two scenarios/builds, testing one one version whilst forward development occurs on the 2nd? Plus probably numerous other scenarios.

Basically – Don’t do it. I see no good reason for qualifying the database name in queries, although as ever I am open to friendly debate via comments!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: