SQL Server - Check if login exists

Compatible from SQL Server 2005

Verify if required login exists and affect workflow. This is simple query to catalog view sys.server_principals . Checking for existence of principal with given name. So this is useful in workflows where you need to create or drop logins from your program.

IF EXISTS (SELECT * FROM master.sys.server_principals WHERE NAME = 'login name') 
	-- do your magic here
ELSE 
	-- do another magic here

Leave a Reply