1

I'm creating a script to automatically configure 2 databases for mirroring, using this how to but I want to make sure there is no end point or master key already created so I would like to first do some clean up as:

DROP ENDPOINT End_Mirroring;
DROP CERTIFICATE PRIM_cert;
DROP MASTER KEY

But how can I do these drops only if they already exist?(i need this to avoid my script to exit with error)

1 Answer 1

5
IF EXISTS ( SELECT * FROM sys.tcp_endpoints WHERE name = 'End_Mirroring')
DROP ENDPOINT End_Mirroring;
IF EXISTS ( SELECT * FROM sys.certificates WHERE name = 'PRIM_cert' )
DROP CERTIFICATE PRIM_cert;
IF EXISTS (SELECT * FROM sys.symmetric_keys WHERE [name] LIKE '%DatabaseMasterKey%')
DROP MASTER KEY";

OK, found it :)

1
  • FYI, almost everything that can be CREATEd, DROPped or ALTERed has a system view to test
    – gbn
    Dec 20, 2011 at 13:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.