V
V
Victor P.2019-02-25 17:22:51
Backup
Victor P., 2019-02-25 17:22:51

How to copy a database from one server to another?

Good afternoon!
I wanted to deal with integration testing issues.
I work with MS SQL server. I need to take the database on one server and copy it to another server, all objects, but without data. To be the same, only on a different server and clean, is this possible? A script so that it can be automated (I can do it manually, but, as far as I understand, this does not turn into a script).
If it is definitely impossible to another server, then at least on the same server.
I want to run from a c# test project, ms tests.
How I imagine it, and how I do it manually: right-click on the database, tasks, generate scripts, by default, the "only schema" item is selected. Next, I upload either to a file or to a page of scripts. I get on the necessary server, there I bang this base, I create anew, I execute the received scripts.
Accordingly, from c#, connecting to one database, executing a command, connecting to another database, resetting it and executing the resulting scripts would be ideal.
How much I dug, this functionality cannot be wrapped in a command. Some third party software is being used.
I would like to make sure, maybe I’m not digging, is it possible to crank out what I’m talking about?
The second option is a little worse. There are bacup database and restore database commands. Is it somehow possible to execute restore database with a script not from the device, but from another database? Schematic only, no data. Either overwrite immediately, or first delete all objects and roll restore from another database. Is that possible?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
Konstantin Tsvetkov, 2019-02-25
@tsklab

Using SSMS create a "Using CREATE" script. Or "Using DROP and CREATE" if the database is already on the server.

E
Evgeny Gribkov, 2019-03-13
@jobgemws

you can do this:
1) create a backup copy
2) copy it to the ball, giving full access to users under which both school services work
3) restore on the second server
This can all be automated, it’s better to do it through the Windows scheduler using a task, and there a PowerShell script shove, because it is difficult to do to item 2 without CMD.
You can also write your own service in general, which will do all this with the settings in a separate configuration file. If there is time and desire, then you can make the face settings and a progress bar

L
lazy, 2019-03-14
Lazy

it is possible to generate a script for their creation from the list of tables and fields in information_schema. Well, the rest of the metadata will have to do the same.
well, changes can certainly be torn out of the transaction log.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question