SQL Server DBA Tutorial 17 - How to Attach and Detach Databases in SQL Server

Опубликовано: 12 Октябрь 2024
на канале: Chirags Tutorial
120
2

[email protected] Chirag's SQL Server DBA Tutorial https://www.chirags.in
*****************************************************************************************
How to attach and detach databases? *
*****************************************************************************************

The data and transaction log files of a database can be detached and then reattached to the same or another instance of SQL Server. Detaching and attaching a database is useful if you want to change the database to a different instance of SQL Server on the same computer or to move the database.

We will be using two ways attach and detach databases
1. Using SQL Server management studio graphic user interface GUI Version
2. Using T-SQL script

/**Detach Script**/
USE [master]
GO
ALTER DATABASE [DVDRental] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
USE [master]
GO
EXEC master.dbo.sp_detach_db @dbname = N'DVDRental'
GO

/**Attach Script**/
USE [master]
GO
CREATE DATABASE [DVDRental] ON
( FILENAME =N'C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER1\MSSQL\DATA\DVDRental.mdf'),
( FILENAME =N'C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER1\MSSQL\DATA\DVDRental_log.ldf')
FOR ATTACH
GO

Note : Flow the Process shown in video.

😉Subscribe and like for more videos:
   / @chiragstutorial  
💛Don't forget to, 💘Follow, 💝Like, 💖Share 💙&, Comment

Tutorial Link :
https://www.chirags.in/tutorials/micr...

Thanks & Regards,
Chitt Ranjan Mahto "Chirag"
_________________________________________________________________________________________
Note: All scripts used in this demo will be available in our website.
Link will be available in description.

#DBATutorial
#DBATutorialLearning
#DBAEducation
#DBATutorialFree
#DatabaseTutorial
#SQLServerDatabaseTutorial
#SQLServerDBATutorial
#MicrosoftSQLServerDatabaseTutorial
#ChiragsDBATutorial
#ChiragsDatabaseTutorial
#ChiragsSQLServerDatabaseTutorial
#ChiragsSQLServerDBATutorial
#Chirags.inSQLServerDBATutorial
#ChiragsMicrosoftSQLServerDatabaseTutorial
#CreateDatabaseinSQLServer
#CreateDatabasewithT-SQL
#chiragstutorial
#databasetutorial
#sqlserver
#sqlservertutorial
#sqlservermanagementstudio
#sql_server
#sqlservertutorial
#chiragstutorial
#databasetutorial
#sqlqueries
#sqldba
#database
#databasemanagement