I want to change default database location? Can anybody explain me how to change the default SQL Server database location via SQL Server Management Studio or Transact-SQL
How to Change the Database Location in SQL Server?
Resolved
SQL
CM
Community Member February 02, 2016
6 replies
797 views
Reviewed by moderators
6 Answers
Open SQL Server Management Studio and right click on the SQL Server Instance. From popup menu, click on propertiesn nFrom server properties dialog box, select a database setting, then change the default database location and click ok. n
nYou need to restart the SQL Server Services to come change into effect
This won’t create the new path for you, this will change the default database to already exists path only
Can you please tell me how to create a new path for existing database in SQL Server
To change the path of an existing databasen
- n
- Issue an ALTER DATABASE. MODIFY FILE command n
- Stop the SQL service n
- Move the database files to a new location n
- Restart the service n
You can also change the path of an existing database using transact-SQLnThen copy the detach database file to a new location nAt last attach the database: n
- n
- First, detach database: n
USE master; nGOnALTER DATABASE DatabaseName SET SINGLE_USER WITH ROLLBACK IMMEDIATE; nGOnEXEC sp_detach_db @databasename = N' DatabaseName' nGOnnnUSE master; nEXEC sp_attach_db @databasename = N' dbName', n@filename1 = N'', --path do. mdfn@filename2 = N'' --path to. ldfnGOnn nYou can try this also that changes the default database location. nn
ALTER DATABASE my SET SINGLE_USER WITH ROLLBACK IMMEDIATE; nnALTER DATABASE my SET OFFLINE; nnALTER DATABASE my MODIFY FILE n(n Name = my_Data, n Filename = ' D:\DATA\my. MDF' n); nnALTER DATABASE my MODIFY FILE n(n Name = my_Log, n Filename = ' D:\DATA\my_1. LDF' n);n