mordi
asked on
How to switch database dynamicaly in T-sql
I have a cursor loop on sysdatabases and i need to query the sysfiles table for each database in system to build an attach script for all databases.
How can i switch the current database dynamicaly inside the cursor. Use keyword doesn't work
How can i switch the current database dynamicaly inside the cursor. Use keyword doesn't work
agree 100% with angelIII- he got me on these... take a look at http://www.databasejournal.com/features/mssql/article.php/3441031
ASKER
Fine.
But there are are several files for each database and i need to build the attach command with all the file names in one line.
But there are are several files for each database and i need to build the attach command with all the file names in one line.
you could cal commands, what is the script you want t use
ASKER
the script is as follows:
sp_attach_db @dbname = N'dbname' , @filename1 = N'db file path' @filename2 = N'db file path', @filename3 = ........
sp_attach_db @dbname = N'dbname' , @filename1 = N'db file path' @filename2 = N'db file path', @filename3 = ........
ASKER
the script is as follows:
sp_attach_db @dbname = N'dbname' , @filename1 = N'db file path' @filename2 = N'db file path', @filename3 = ........
sp_attach_db @dbname = N'dbname' , @filename1 = N'db file path' @filename2 = N'db file path', @filename3 = ........
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thanks angelIII - my email stopped and did not get notified
here a small sample:
exec sp_MSForEachDb ' select * from ?..sysfiles '