How to delete an endpoint only if exists 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)
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 :)