There is a handy little "by product", if you like, when running queries which means you can quickly generate scripts to do different things. Below is an example of generating multiple "attach" commands that you can copy from the results pane into the main SSMS window for execution. I have found this very handy in the past:
SELECT
'CREATE DATABASE [' +
name +'] ON
( FILENAME = N''F:\MSSQL\Data\' +
name + '.mdf'' ),
( FILENAME = N''E:\MSSQL\Log\' +
name + '_log.ldf'' )
FOR ATTACH
GO
'
FROM master.dbo.sysdatabases
WHERE name not in ('master','msdb','model','tempdb')
ORDER BY name
Comments
Post a Comment