Skip to main content

How to relocate or move user Database in same instance - SQL SERVER 2005/2008

Move or Relocate Database  (Data file and Log file) of User Database in same instance:




Step 1: Run the command to find the present path of DB

SELECT name, physical_name
FROM sys.master_files where name like '%AdventureWorksDW%'




Step 2: Bring Database Offline.
  
alter database AdventureWorksDW set offline with rollback immediate ;
 




Step 3: Copy/Cut Paste the physical files.

Copy/Cut the Data file and log file  from Source:
Paste to Destination( new path or location):


Step 4: Run the below command to locate in new path for mdf.

alter database AdventureWorksDW
modify file (name=AdventureWorksDW_Data , filename='E:\SQL2005\Instance2\AdventureWorksDW_Data.mdf');


Step 5: Run the below command to locate in new path for ldf.
       (same for ndf also with proper logical name and extension)

alter database AdventureWorksDW
modify file (name=AdventureWorksDW_Log , filename='E:\SQL2005\Instance2\AdventureWorksDW_log.ldf');


Step 6: Validate the new location.
SELECT name, physical_name
FROM sys.master_files where name like '%AdventureWorksDW%'




Step 7: Bring Database Online

alter database AdventureWorksDW set online;




This procedure I follow in Production Database. Downtime require only for the Database which you will do the activity and the Downtime of that Database depends on its size.

For any query regarding Move or Relocate Database  (Data file and Log file) of User Database in same instance, please email me : rizwan2007ali@gmail.com












Comments

Popular posts from this blog

Different types of Database Restore option

RESTORE FILELISTONLY retrieves the list of database and log files in the backup. RESTORE HEADERONLY returns header information about all backup sets on the supplied backup device. Although this command returns a wealth of information, typically you will only examine a small portion of it. For instance, it might be beneficial to know a backed up database’s collation, type of backup, first and last Log Sequence Numbers and database compatibility level. RESTORE FILELISTONLY FROM DISK = 'e:\telefullbkp' RESTORE HEADERONLY FROM DISK = 'e:\telefullbkp' RESTORE FILELISTONLY FROM DISK = 'D:\backup\Banking_20120929192001.trn' RESTORE HEADERONLY FROM DISK = 'D:\backup\Banking_20120929192001.trn' ********************************************************************************************* /* restore the full backup first with NO RECOVERY */ RESTORE DATABASE pubs FROM DISK = 'e:\pubs.bak' WITH...

All about View in SQL Server

View :: Any relation which is not part of logical model,but is made visible to a user as a virtual relation, is called a view. --CREATE VIEW [ schema_name . ] view_name [ (column [ ,...n ] ) ] [ WITH <view_attribute> [ ,...n ] ] AS select_statement [ ; ] [ WITH CHECK OPTION ] < view_attribute > ::= { [ ENCRYPTION ] [ SCHEMABINDING ] [ VIEW_METADATA ] } ----------------------------------------------------------------------------------------- ENCRYPTION : The definition of an encrypted view is not visible to anyone, including a member of the sysadmin fixed server role.cannot decrypt the definition. SCHEMABINDING : cannot drop any tables, views, or functions referenced by the view without first dropping the view. VIEW_METADATA : ----------------- Example:CREATE VIEW v_CustomerAddress AS SELECT a . CustomerID , a . CustomerName , c . AddressLine1 , c . AddressLine2 , c . AddressLine3 , c . City , d . StateProvince , c . P...

How to install SQL Server 2005 step by step

How to install SQL Server 2005 step by step