SQL script to “copy” a database

后端 未结 7 607
名媛妹妹
名媛妹妹 2020-12-14 20:46

I want to write a SQL script that will copy a database on the same server. I could do a backup/restore, but I think it might be faster to just \"copy\" somehow. Does anyon

7条回答
  •  隐瞒了意图╮
    2020-12-14 21:32

    Is there a way to write a script that will just detach, copy the file on the HD, and then reattach both copies?

    Yes. For detaching and attaching you can use sp_detach_db and sp_attach_db. For copying the files, you can use xp_cmdshell and xcopy.

    Still, I think the backup-and-restore approach is easier, since it does not require you to copy the files.

提交回复
热议问题