|
-
Nov 21st, 2007, 04:46 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] [sql 2k5] DROP TSQL
a simple question how to drop a database with the use of IF stmt to check if the object exist.
if object_id('dbo.myDB') is not null
drop database 'myDB'
go
the code returns no error but it also wont delete the database("myDB")
-
Nov 21st, 2007, 07:28 AM
#2
Re: [sql 2k5] DROP TSQL
You DROP tables, not databases.
To remove a database from disk use DELETE DATABASE dbname
-
Nov 21st, 2007, 08:10 AM
#3
Thread Starter
Fanatic Member
Re: [sql 2k5] DROP TSQL
hi hack there was an error return when i execute the script
-
Nov 21st, 2007, 08:16 AM
#4
Re: [sql 2k5] DROP TSQL
Try this:
vb Code:
USE [master]
GO
IF EXISTS (SELECT name FROM sys.databases WHERE name = N'DBName')
DROP DATABASE [DBName]
Edit: All I did was right click on the Database ---> Script Database as ---> Drop To ---> Clipboard.
Last edited by Mark Gambo; Nov 21st, 2007 at 08:22 AM.
Reason: Added data
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
-
Nov 21st, 2007, 08:21 AM
#5
Thread Starter
Fanatic Member
Re: [sql 2k5] DROP TSQL
why im getting this error:
Msg 3702, Level 16, State 4, Line 4
Cannot drop database "DBname" because it is currently in use.
the database was not in use/design mode/open by any application
-
Nov 21st, 2007, 08:24 AM
#6
Re: [sql 2k5] DROP TSQL
 Originally Posted by jlbantang
why im getting this error:
Msg 3702, Level 16, State 4, Line 4
Cannot drop database "DBname" because it is currently in use.
the database was not in use/design mode/open by any application
Check the Activity Monitor and make sure that there aren't any connections to the database. If not, then depending upon your setup you may have to stop and then restart SQL Server.
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
-
Nov 21st, 2007, 08:25 AM
#7
Thread Starter
Fanatic Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|