July 10, 2007 at 10:27 am
My application creates a new database in the C:\program files\microsoft\MSSQL......\Data location. I would like to change the default installation location for new DB's. Is there a way to do this? Possibly by changing a registry setting. I do not want to uninstall and reinstall my MSSQL to a different drive.
July 10, 2007 at 10:40 am
DECLARE @data_path nvarchar(256);
SET
@data_path = 'What ever you want'
--execute the CREATE DATABASE statement
EXECUTE
('CREATE DATABASE Test
ON
( NAME = Test_dat,
FILENAME = '''
+ @data_path + 'testdat.mdf'',
SIZE = 10,
MAXSIZE = 50,
FILEGROWTH = 5 )
LOG ON
( NAME = Test_log,
FILENAME = '''
+ @data_path + 'testlog.ldf'',
SIZE = 5MB,
MAXSIZE = 25MB,
FILEGROWTH = 5MB )'
);
GO
July 10, 2007 at 11:45 am
The default directories can be set at the server level.
Go to properties, database settings and you will see a place for Database default locations. This is the same in both Enterprise Manager and SQL Server Management Studio.
Regards,
Rubes
July 11, 2007 at 12:42 am
Once you set the default in the EM then all/any databases created without path will take the default location specified this can be only override specifying the location when you create the database.
Cheers,
Sugeshkumar Rajendran
SQL Server MVP
http://sugeshkr.blogspot.com
July 11, 2007 at 2:33 am
July 11, 2007 at 4:59 am
The default location specified in Enterprise Manager only applys when creating the database with Enterprise Manager and has no effect on the database file locations when using the command "CREATE DATABASE".
For a "CREATE DATABASE" without any file location specification, the files will be created in the same locations as the model database.
This has been tested.
SQL = Scarcely Qualifies as a Language
July 11, 2007 at 5:03 am
Accepted from query analyzer if you don't specify the path the path of the model database is taken for creating the database.
Cheers,
Sugeshkumar Rajendran
SQL Server MVP
http://sugeshkr.blogspot.com
July 11, 2007 at 6:46 am
I made the change in EM and tried building the DB. I worked like a champ. Thanks to all for your suggestions.
July 11, 2007 at 6:50 am
Dave,
If you want to do this from an app or even TSQL itself, see the following script for how to do it... and, yes, it is a registry change...
http://www.sqlservercentral.com/scripts/viewscript.asp?scriptid=1854
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply