Using SMO to copy a database and data

后端 未结 4 1019
陌清茗
陌清茗 2021-01-31 18:49

I am trying to make a copy of a database to a new database on the same server. The server is my local computer running SQL 2008 Express under Windows XP. Doing this should be q

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-31 19:44

    Here is my solution:

    1. I have a Database named is Olddatabase
    2. I backup it to E:\databackup\Old.bak

    3. If you want to create a Duplicate Database from Olddatabase in the same server with name NewDatabase

    3.1 You can use command in query tool : EXEC OldDatabase.dbo.sp_helpfile; to determinat path of OldDatabase is stored in case you want to save NewDatabase in the same folder.

    or You can save NewDatabase in new Path which you want

    1. use this command in Query tool

      RESTORE DATABASE NewDatabase FROM DISK = 'E:\databackup\Old.bak' WITH MOVE 'OldDatabase' TO 'E:\New path (or the same path)\NewDatabase_Data.mdf', MOVE 'OldDatabase_log' TO 'E:\New path (or the same path)\NewDatabase_Log.ldf';

    Note: you can Use these command obove in c# with : Create a Store procedure in sql which include Above commands. And you can call the store procedure in C #

提交回复
热议问题