SQL-Server-Notes

SQL-Server-Notes.                              Download

Generate Attach and Detach Database Script for All User Databases on SQL Instance


Managing your SQL Server databases often requires attaching and detaching databases. Below is a T-SQL script to generate the attach and detach commands for all user databases on a SQL Server instance. This script can be used on SQL Server versions 2008, 2012, 2014, and 2016.

Script to Generate Attach and Detach Commands