|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Monday, February 04, 2013 5:03 AM
Points: 4,
Visits: 16
|
|
| please help me, how to attach database with variable path??
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Yesterday @ 1:28 PM
Points: 6,698,
Visits: 11,726
|
|
It requires a bit of dynamic sql:
USE master;
DECLARE @dbname SYSNAME = N'AdventureWorks2008R2', @filename NVARCHAR(500) = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQL2008R2DEV\MSSQL\DATA\AdventureWorks2008R2_Data.mdf', @logfilename NVARCHAR(500) = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQL2008R2DEV\MSSQL\DATA\AdventureWorks2008R2_log.LDF', @sql NVARCHAR(MAX);
SET @sql = N'CREATE DATABASE ' + QUOTENAME(@dbname) + N' ON ( FILENAME = N' + QUOTENAME(@filename, '''') + N'), ( FILENAME = N' + QUOTENAME(@logfilename, '''') + N') FOR ATTACH;'
PRINT @sql
--uncomment when ready --EXEC(@sql); GO
__________________________________________________________________________________________________ There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Believe you can and you're halfway there. --Theodore Roosevelt
Everything Should Be Made as Simple as Possible, But Not Simpler --Albert Einstein
The significant problems we face cannot be solved at the same level of thinking we were at when we created them. --Albert Einstein
1 apple is not exactly 1/8 of 8 apples. Because there are no absolutely identical apples. --Giordy
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Monday, February 04, 2013 5:03 AM
Points: 4,
Visits: 16
|
|
ok thanks very much  its resolved
|
|
|
|