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
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.


jayakrishnan Morayur156 reputationPosted Mar 4, 2011, 9:47 PM EST
-- 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