What would be the best way to transfer my (small) SQL Server database between two locations?

I am working on a project where I am the only person working on it. I try to do everything with "best practice" in mind as much as possible.

I am working on a project from two locations - PC to PC and home PC. I make regular commits to a Git repository and keep both locations up to date that way.

Over the weekend I implemented a small SQL Server database with my application, went to work today and found the .mdf

files were automatically on mine .gitignore

.

Did some digging and it looks like it should stay this way. I looked at the source controlling the database but everything seems to point to expensive software or some kind of tool that I cannot figure out.

What would be the best way to keep not only the structure of this database, but the data content of the database the same between my parents and my workplaces? Should I remove .mdf

from the original control and do it this way? Or would it be better to do XYZ?

+3


source to share


2 answers


It would be easy to just back up in one location and restore to another. You can take this backup and restore with free SSMS or just in code if you like. You can zip the generated .bak file. This is one of the easiest ways.



You can detach and attach mdf files as well, but it's easier for me to manage the backup.

+1


source


Extra options:

You can create scripts to create / modify a database with all data included. into the insert / update statement. Or you can save the data to a csv and populate it script. and save these script and csv data files in any source control tool.

There are two modifications:



  • The scripts drop the existing database and then create it from scratch as in the sqlfiddle .

  • Scripts that can update any existing version of the database to the current version without deleting the data

The second way is more complex, but sometimes it may be the only way for enterprise systems because of the many versions in many environments and the need to leave test and production data intact.

So, I think that the first of the proposed versions is more suitable for your case.

+1


source







All Articles