vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| |||
| fireball (fireball@onet.kropka.eu) writes: > which is more proper: > if DB_ID(@db) IS NOT NULL > or > IF EXISTS (SELECT name FROM sys.databases WHERE name = @db) > ? Whichever you fancy. I would probably write the second nine times out of ten, but that it would only be because db_id() would not come in my mind. And a nice characteristic of the first, is that it works on SQL 2000 as well. -- Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se Books Online for SQL Server 2005 at http://www.microsoft.com/technet/pro...ads/books.mspx Books Online for SQL Server 2000 at http://www.microsoft.com/sql/prodinf...ons/books.mspx |
| |||
| fireball (fireball@onet.kropka.eu) writes: >> I would probably write the second > [...] > > thank you. > so you would say, first solution is not less professional at all then the > second one.. - right? Yes, both are perfectly OK, and which you pick is a matter of taste or the flux of the moment. -- Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se Books Online for SQL Server 2005 at http://www.microsoft.com/technet/pro...ads/books.mspx Books Online for SQL Server 2000 at http://www.microsoft.com/sql/prodinf...ons/books.mspx |
| ||||
| The first one; its more portable between versions of SQL Server, the second only works in SQL 2005 and upwards. -- Tony Rogerson SQL Server MVP http://sqlblogcasts.com/blogs/tonyrogerson - technical commentary from a SQL Server Consultant http://sqlserverfaq.com - free video tutorials "fireball" <fireball@onet.kropka.eu> wrote in message news:embrdl$n8d$1@atlantis.news.tpi.pl... > which is more proper: > if DB_ID(@db) IS NOT NULL > or > IF EXISTS (SELECT name FROM sys.databases WHERE name = @db) > ? > > > > > regards > > |