I want to drop a database programmingly. Following is my code:
'---------------------------------------
CREATE PROCEDURE PROC_DELETE_DB
@dbname varchar(50)
AS
IF EXISTS(SELECT * FROM MASTER..SYSDATABASES WHERE NAME=@dbname)
BEGIN
DROP DATABASE @dbname
END
'-------------------------------------
Unfortunately, It doesn't work and the error is in "DROP DATABASE" statment.
I tried the following in QA:
'----------------------
DROP DATABASE 'test_db'
'----------------------
It generate the same error. but this statement is ok:
'-----------------------
DROP DATABASE test_db
'-----------------------
So, how can I make my procedure work with
'---------------------
DROP DATABASE @dbname
'---------------------
'---------------------------------------
CREATE PROCEDURE PROC_DELETE_DB
@dbname varchar(50)
AS
IF EXISTS(SELECT * FROM MASTER..SYSDATABASES WHERE NAME=@dbname)
BEGIN
DROP DATABASE @dbname
END
'-------------------------------------
Unfortunately, It doesn't work and the error is in "DROP DATABASE" statment.
I tried the following in QA:
'----------------------
DROP DATABASE 'test_db'
'----------------------
It generate the same error. but this statement is ok:
'-----------------------
DROP DATABASE test_db
'-----------------------
So, how can I make my procedure work with
'---------------------
DROP DATABASE @dbname
'---------------------