|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Friday, May 17, 2013 3:01 AM
Points: 83,
Visits: 320
|
|
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.
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Yesterday @ 11:14 PM
Points: 6,706,
Visits: 11,738
|
|
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
Believe you can and you're halfway there. --Theodore Roosevelt
Everything Should Be Made as Simple as Possible, But Not Simpler --Albert Einstein
The significant problems we face cannot be solved at the same level of thinking we were at when we created them. --Albert Einstein
1 apple is not exactly 1/8 of 8 apples. Because there are no absolutely identical apples. --Giordy
|
|
|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Friday, May 17, 2013 3:01 AM
Points: 83,
Visits: 320
|
|
| We need to something to do with having a stored procedure that someone could execute that could create a new database on the instance?
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Yesterday @ 11:14 PM
Points: 6,706,
Visits: 11,738
|
|
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
Believe you can and you're halfway there. --Theodore Roosevelt
Everything Should Be Made as Simple as Possible, But Not Simpler --Albert Einstein
The significant problems we face cannot be solved at the same level of thinking we were at when we created them. --Albert Einstein
1 apple is not exactly 1/8 of 8 apples. Because there are no absolutely identical apples. --Giordy
|
|
|
|