Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

how to attach database with variable path by storedprocedure?? Expand / Collapse
Author
Message
Posted Sunday, January 27, 2013 7:25 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum 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??
Post #1412126
Posted Sunday, January 27, 2013 8:58 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

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
Post #1412131
Posted Monday, January 28, 2013 3:32 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, February 04, 2013 5:03 AM
Points: 4, Visits: 16
ok thanks very much
its resolved
Post #1412295
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse