We recently had a server migration. A new server is now the PROD server, and what used to be the PROD server is now the staging environment.
Apparently, the data was transferred correctly, but the database is missing its PK/FK contraints. Luckily, the database hasn't been touched yet as the connected application is still in migration, which means that if the PK/FK constraints are now enabled, there shouldn't be any issues because no rows were created/altered/deleted.
We stil have the original database (which is now staging). The structure is the same, but the content has already changed numerous times during dev testing.
Is there a way in which I can keep the current PROD database, and add the PK/FK constraints to it (based on the staging database)?
Extra info:
- we have no backups readily available unfortunately, else I would've fixed it that way
- Using SQL Server 2008 via SSMS
- I'm not the one who performed the data migration. It is office procedure to move databases by using .bak files, but I fear someone used the import/export option, hence losing the PK/FK constraints.
Best Answer
Script out the constraints from the staging database and apply to the problem database. Lots of options, just make sure you have backups of staging and prod before you start: