How To Recover a Deleted Estimate

I deleted my estimate and need to get it back

Occasionally, a client may accidentally delete an estimate, the delete is a "soft delete" which means it flag it to remove from view to the user but it is still in the database. 

The script below can be used to set the estimate back to a state where it is accessible to the users. This can only be done by the IT department/DBA. 

The will be done against your DESTINIData or the name of your Project database if it was changed from DESTINIData.

If you are not sure of the exact name of the estimate, it can be found in the dbo.Estimates table of that database. 

DECLARE @EstimateName VARCHAR(100)= 'Demo_Conceptual';
UPDATE dbo.EstimateContainers
SET
IsDeleted = 0
WHERE [Key] IN
(SELECT ec.[Key]
FROM dbo.EstimateContainers ec
JOIN dbo.estimates e ON e.[key] = ec.EstimateKey
WHERE estimatename = @EstimateName
AND ec.IsDeleted = 1)

Steps:

1. In SSMS, Open a New Query and copy the above script.

2. In line 1, make sure that the "Demo_Conceptual" is changed to the name of the estimate that you want to restore.

3. In the database drop-down window, make sure that the "Project" database is selected. 

4. Click the Execute button to update your changes. 

Next open Estimator and search for the estimate. 

This query should return all estimates that have been deleted along with who/when deleted, happened.

SELECT [Estimates].[Key] AS 'EstimateKey', [Estimates].[EstimateName], [EstimateContainers].[LastUpdateDatetime] AS 'DeletedDateTime', [EstimateContainers].[LastUpdatedBy] AS 'DeletedBy'
FROM [EstimateContainers] INNER JOIN [Estimates] ON [EstimateContainers].[EstimateKey] = [Estimates].[Key]
WHERE [EstimateContainers].[IsDeleted] = 1