Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 drop database [variable]

Author  Topic 

GRAYWOLF
Posting Yak Master

106 Posts

Posted - 2008-12-25 : 01:40:51
I have a script that creates a DB from backup...then tests it...Then I am trying to drop it. How do I use a variable as the object DB?

DROP DATABASE [@newdbname]
DROP DATABASE ''@newdbname''
DROP DATABASE @newdbname
DROP DATABASE ''+@newdbname+''

None of the above works...



---------------------------

Working until "the morning sun sets the midnight sky on fire"!

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-25 : 01:44:39
[code]EXEC ('DROP DATABASE' + @newdbname)[/code]
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-12-25 : 10:11:06
You'll need to add a space to visakh's: EXEC ('DROP DATABASE ' + @newdbname)


Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -