Create a database with dynamic name by using storedproceure
How can create a database using stored procedure but the database name is passed as parameter or how can i create a database with dynamic name
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
jayakrishnan MorayurPosted Mar 5, 2011, 2:47 AM
-- Add the parameters for the stored procedure here
@DBName varchar(max)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
Declare @dbString varchar(max)
set @dbString = 'CREATE DATABASE ' + @DBName
exec(@dbString)
END
GO