Chandler

导航

sql2005 数据库附加

1)Copy the .mdf and .ldf files to a folder on the SQL Server computer, and name them
   with a name you like. This is how I named mine:

   C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\xxx.mdf
   C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\xxx_Log.ldf

 

2) Open SQL Server Management Studio, and start a new query, and connect to your
   database instance and the master database.

3) Key in this query and press F5 to run it (use the same paths as step 1):
  
   exec sp_attach_db @dbname=N'xxx',
     @filename1=N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\xxx.mdf',
     @filename2=N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\xxx_Log.ldf'

4) Replace the query in your query window with this code and press F5 to run it - please
   make changes to the user credentials first - NEVER use the same username and password
   as those that come from a book or Internet site:

USE xxx

GO
EXEC sp_addlogin 'DBuserName', 'SecretPassword', 'xxx'
GO
EXEC sp_grantdbaccess 'DBuserName', 'DBuserName'
GO
EXEC sp_addrolemember 'db_datareader', 'DBuserName'
GO
EXEC sp_addrolemember 'db_datawriter', 'DBuserName'
GO
EXEC sp_addrolemember 'db_owner', 'DBuserName'
GO

 

posted on 2009-04-07 10:24  Chandler.C  阅读(307)  评论(0编辑  收藏  举报