Wednesday, 13 July 2011

How to attach and deattached database in sql server by T-sql ?

Please use the below query :

For Attach :

USE
GO
[master]CREATE DATABASE [abc] ON (
(
FILENAME = N'D:\sql_data\abc.mdf' ), FILENAME = N'D:\sql_data\abc_log.ldf' )
GO

For Deattach :

USE
GO
[master]EXEC master.dbo.sp_detach_db @dbname = N'abc', @keepfulltextindexfile=N'true'GO

After that refersh the database tab and check your currently attached data base.
FOR ATTACH

No comments:

Post a Comment