Checking if a SQL Server login already exists
Here’s a way to do this in SQL Server 2005 and later without using the deprecated syslogins view: IF NOT EXISTS (SELECT name FROM master.sys.server_principals WHERE name=”LoginName”) BEGIN CREATE LOGIN [LoginName] WITH PASSWORD = N’password’ END The server_principals view is used instead of sql_logins because the latter doesn’t list Windows logins. If you need to … Read more