April 10, 2015 at 8:50 am
Comments posted to this topic are about the item Check existence of a database
Thanks.
April 21, 2015 at 6:04 am
Why didn't you use an ELSE statement to prevent the need for 2 calls?
April 21, 2015 at 6:54 am
I don't know how "Featured Scripts" are chosen. As LuckyNickyBoy observed the procedure is inefficient as it executes 4 tests where 2 are needed. Also, it uses the deprecated compatibility view sysdatabases instead of the replacement catalog view sys.databases. From BOL https://msdn.microsoft.com/en-us/library/ms179900.aspx "This SQL Server 2000 system table is included as a view for backward compatibility. We recommend that you use the current SQL Server system views instead." Even if I chose to use a deprecated view for some reason, I would use the sys schema, not dbo. Finally, returning 'YES' or 'NO' is not a choice I would make.
April 21, 2015 at 8:26 am
Check out DB_ID() https://msdn.microsoft.com/en-us/library/ms186274.aspx
April 21, 2015 at 8:27 am
I agree. You'd expect the specifically-chosen (?) "featured script" to be something at least moderately good/useful, but most often they are not.
As for this code, I would suggest simply:
SELECT CASE WHEN DB_ID (@dbname) IS NULL THEN 'NO' ELSE 'YES' END
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
April 21, 2015 at 11:02 am
Thanks for the tip.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy