January 25, 2013 at 1:42 am
Hi,
Is there any way to create the database using stored procedure ? We want to create the database using stored procedure which is the best way to handle it?
Regards,
Ram.
January 25, 2013 at 7:08 am
Are you asking whether you should design your database to only allow accessing data via stored procedures? Or something to do with having a stored procedure that someone could execute that could create a new database on the instance? Can you please clarify?
There are no special teachers of virtue, because virtue is taught by the whole community.
--Plato
January 25, 2013 at 7:26 am
We need to something to do with having a stored procedure that someone could execute that could create a new database on the instance?
January 25, 2013 at 7:37 am
In its simplest form:
CREATE PROC dbo.createnewdb (@dbname SYSNAME)
AS
BEGIN
DECLARE @sql NVARCHAR(MAX) = N'CREATE DATABASE ' + QUOTENAME(@dbname);
EXEC(@sql);
END
GO
EXEC dbo.createnewdb N'newdb';
There are too many considerations to list here before creating a stored procedure like this and allowing folks to call it but something like I showed should get you started.
There are no special teachers of virtue, because virtue is taught by the whole community.
--Plato
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply