Merging a .bak to an existing SQL database I have a SQL Server database with data from 1990-2018 in a .mdf file.
I recently downloaded data for 2018-2020 and it's in a .bak file.
When I went to &quot;Restore&quot; the database, it wiped out all the data from 1990-2018 and just replaced it with the new one (2018-2020).
How do I merge an existing .mdf and a new .bak file? Or am I just thinking about this wrong?
A single database restore is not the operation you need if your goal is the merge data. You are looking for a data level solution not a database level solution.
SQL tooling can help you with this task, but it is not required (it depends on knowledge and skill level). The 2 data compare tools I have used Red Gate SQL Data Compare and Apex SQL Data Diff have the ability to compare data using a .bak file. After the comparison the tool can generate the 'deployment' or 'change' script that you could use to &quot;merge&quot; in your changes.
TSQL solution: Craft a merge statement for each table. This would require restoring your backup file to another Database name.  This will result in 2 databases (source and target) living on the SQL Server.
TSQL Merge docs:
https://docs.microsoft.com/en-us/sql/t-sql/statements/merge-transact-sql?view=sql-server-ver15
To avoid a database overwrite specify a new destination (non-existing) database name in your restore command. (included SSMS screen shot)