Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Is there any way to create the database using stored procedure which includes design Expand / Collapse
Author
Message
Posted Friday, January 25, 2013 1:42 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Wednesday, July 23, 2014 10:49 PM
Points: 90, Visits: 388
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.

Post #1411520
Posted Friday, January 25, 2013 7:08 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 9:23 AM
Points: 7,098, Visits: 12,605
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
Post #1411704
Posted Friday, January 25, 2013 7:26 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Wednesday, July 23, 2014 10:49 PM
Points: 90, Visits: 388
We need to something to do with having a stored procedure that someone could execute that could create a new database on the instance?
Post #1411716
Posted Friday, January 25, 2013 7:37 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 9:23 AM
Points: 7,098, Visits: 12,605
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
Post #1411726
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse