Asked By
Cameron1qaz
0 points
N/A
Posted on - 09/15/2011
Hi,
One of my friend has given me a Microsoft SQL Database.
How can I attach it to my database server.
The files I got are as follows.
myproject1.mdf
Can you please put down all the steps how to attach this DB?
Thanks,
Cameron
How do I attach an external SQL Server DB
sp_attach_db system stored procedure can be used to attach a database with the following syntax:
sp_attach_db [ @dbname = ] 'dbname',
            [ @filename1 = ] 'filename_n' [ ,…16 ]
sp_attach_single_file_db system stored procedure can be used, to attach a single file with this syntax:
sp_attach_single_file_db [ @dbname = ] 'dbname'
   , [ @physname = ] 'physical_name'Â
@dbname is the name of the database while @physname is the database file name.
How do I attach an external SQL Server DB
Hello Cameron,
Thanks for sharing your problem with us on this growing information technology website.
Dear it is so easy to attach a new file you have downloaded or got from friend.
Just type these codes with the same syntax,
sp_attach_single_file_db [ @dbname= ] 'dbname' Â Â Â Â , [ @physname= ] 'physical_name' Arguments: Here, (@dbname)'physical_name' is the name of the file which you want to attach or upload to the SQL Server. And (@physname) Is also the name of file but with the complete location or address of the file.
When you will finish this step you will get return codes value.
If you got 0 it means the process was successful, if you got 1 it represent of a failure.
Thanks i hope you are satisfied on this solution.