手上有一些档案
档案的格式为
A.mdf A_log.ldf
B.mdf B_log.ldf
都放在 C:\MSSQL\DATA\ 下
想要输出格式为
EXEC sp_attach_db @dbname = 'A'
,@filename1 = 'C:\MSSQL\DATA\A.MDF'
,@filename2 = 'C:\MSSQL\DATA\A_Log.LDF'
EXEC sp_attach_db @dbname = 'B'
,@filename1 = 'C:\MSSQL\DATA\B.MDF'
,@filename2 = 'C:\MSSQL\DATA\B_Log.LDF'
的内容
目前有参考的写法
add.bat
FOR %%I IN (*.mdf) DO ECHO EXEC sp_attach_db @dbname = '%%~nI' >> add.sql
FOR %%I IN (*.mdf) DO ECHO ,@filename1 = '%%~dpnxI' >> add.sql
FOR %%I IN (*.ldf) DO ECHO ,@filename2 = '%%~dpnxI' >> add.sql
ECHO.
但是输出以后格式为
EXEC sp_attach_db @dbname = 'A'
EXEC sp_attach_db @dbname = 'B'
,@filename1 = 'c:\MSSQL\DATA\A.mdf'
,@filename1 = 'c:\MSSQL\DATA\B.mdf'
,@filename2 = 'c:\MSSQL\DATA\A_log.LDF'
,@filename2 = 'c:\MSSQL\DATA\B_log.LDF'
不知道有没有哪位可以指点一下这要怎么修改~Orz