How to check if a Credential exists in a SQL Server instance?

10,133
if exists (select * from sys.credentials where name = 'CredName')
    drop credential CredName
Share:
10,133

Related videos on Youtube

Dan
Author by

Dan

Contracting in anything interesting with Microsoft technologies, primarily middle/back-end in C#, BizTalk, Azure, SQL Server, WCF, SSIS, etc. Currently working at Wokingham Borough Council on integrations using Dynamics CRM Online, Azure Service Bus and various back office systems. Please feel free to contact me if you've got an interesting project ...

Updated on June 04, 2022

Comments

  • Dan
    Dan about 2 years

    How can you check if a Credential already exists in a SQL Server instance, so as to avoid an error when running a DROP CREDENTIAL ?

    Normally I use the SCRIPT AS ... and DROP And CREATE To feature in SSMS to create the script, but the CREDENTIAL doesn't have that option

  • Dan
    Dan about 12 years
    Thank you ... any idea why the DROP / CREATE option isn't on the SSMS menu like with the rest of the database artefacts?
  • Andomar
    Andomar about 12 years
    It's not present in SSMS 2012 either, and the Properties -> Script Action As button doesn't work. No idea why.
  • Ben Thul
    Ben Thul about 12 years
    The existence or not of a feature in SSMS is typically bijective of whether or not the feature exists in SMO. However, in this case, it seems not to be the case. Specifically, a Drop() method exists on the Microsoft.SqlServer.Management.Smo.Credential class. I just tested it with a dummy credential and it works. I've logged a Connect option here: connect.microsoft.com/SQLServer/feedback/details/747691/….