How do I copy SQL Server 2012 database to localdb instance?

后端 未结 9 1906
你的背包
你的背包 2021-02-04 00:49

I\'m looking to copy a SQL Server 2012 Standard database to my localdb instance. I\'ve tried the wizard which complains that localdb isn\'t a SQL Server 2005 or later expres

9条回答
  •  旧时难觅i
    2021-02-04 01:25

    I had the same issue, and after doing a little online research I came across an ingenious way to get it to work (albeit quite hacky). Basically, you:

    1. Create a SqlLocalDb instance (SqlLocalDb c tmp -s).
    2. Restore the database as you did above (e.g., SqlCmd -E -S -Q "RESTORE DATABASE ...").
    3. Stop the SqlLocalDb instance (SqlLocalDb p tmp).
    4. Delete the SqlLocalDb instance (SqlLocalDb d tmp).
    5. Create a new SqlLocalDb instance (SqlLocalDb c persistent -s).
    6. Create the database in the new instance by attaching it (SqlCmd -E -S -Q "Create Database On (Filename = ') For Attach".

    And hopefully it should work. See here for original idea.

    Edit: Added Jason Brady's correction of the create command.

提交回复
热议问题