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
Related videos on Youtube
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, 2022Comments
-
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 ...
andDROP And CREATE To
feature in SSMS to create the script, but theCREDENTIAL
doesn't have that option -
Dan about 12 yearsThank you ... any idea why the DROP / CREATE option isn't on the SSMS menu like with the rest of the database artefacts?
-
Andomar about 12 yearsIt's not present in SSMS 2012 either, and the
Properties -> Script Action As
button doesn't work. No idea why. -
Ben Thul about 12 yearsThe 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/….