You are here: Re: when to use fully qualified names ([database].[schema].object) « MsSQL Server « IT news, forums, messages
Re: when to use fully qualified names ([database].[schema].object)

Posted by Erland Sommarskog on 01/02/07 22:20

fireball (fireball@onet.kropka.eu) writes:
> Uzytkownik "Erland Sommarskog" <esquel@sommarskog.se> napisal w wiadomosci
>> Use two-part names, not three-part names.
> but why??
>
>
> I wisht to say, for example:
>
> SELECT * FROM somebase.sys.schemas
> WHERE name = N'someschema'
>
> or (- I don't know which query will be more proper, to obtain schema of
> given database):
>
> SELECT * FROM somebase.INFORMATION_SCHEMA.SCHEMATA
> WHERE SCHEMA_NAME = N'someschema'
>
> but without saying:
> USE somebase
>
>
> - (why) is that wrong solution?
> hint: I parametrize my database name in my scripts.

There is not much context in your posts, so the answers you get tend to
be generic.

The problem with specifying the database in application code is that
you get problems if you want to run a second environment on the same
server.

Apparently you are writing some scripts. I would say that the same thing
applies where: the fewer places you specify the database name, the
easier is to change the script to run for a different database.

Now you say that you parameterise the database name in the script. I guess
this is one of the SQLCMD variables, that I will have to admit not paid
too much attention to. If you have a script variable that holds the
database name, I guess it's OK.

But I don't know what your scripts are doing, so it's difficult to say
for sure.


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация