all groups > sql server programming > november 2005 >
You're in the

sql server programming

group:

SQL2K5: Check if login already exists


Re: SQL2K5: Check if login already exists Kent Tegels
11/17/2005 2:26:35 PM
sql server programming:
Hello Graham,

[quoted text, click to view]

I use
if (select count(*) from sys.server_principals where type = 's' and name=N'user')
[quoted text, click to view]


Thank you,
Kent Tegels
DevelopMentor
http://staff.develop.com/ktegels/

Re: SQL2K5: Check if login already exists Aaron Bertrand [SQL Server MVP]
11/17/2005 5:23:47 PM
You should familiarize yourself with the new catalog views, because they are
replacing all of the old system tables.

Try out

master.sys.sql_logins
master.sys.server_principals

sql_logins has some extra information about password:
policy/expiration/hash.

A




[quoted text, click to view]

Re: SQL2K5: Check if login already exists Aaron Bertrand [SQL Server MVP]
11/17/2005 5:51:40 PM
[quoted text, click to view]

Well, you can use master.dbo.syslogins instead of sysxlogins. But it is
being phased out, so eventually you will have to let go of scripts that
"just work" across 8 different versions.

SQL2K5: Check if login already exists Graham Smith
11/17/2005 11:12:59 PM
Hi,

the following statement fails on SQL 2K5:

if not exists(SELECT * FROM master.dbo.sysxlogins where Name=N'User')
begin
exec sp_addLogin 'User', 'test', 'User'
end

Does anybody know how to check if login already exists with SQL Server 2005?

Thanks in advance
Graham

--
Graham Smith

Re: SQL2K5: Check if login already exists Graham Smith
11/17/2005 11:37:06 PM
Hi,

does that mean that this cannot be scripted to work both in SQL 2k and 2k5?

Thanks in advance
Graham

--
Graham Smith

[quoted text, click to view]

AddThis Social Bookmark Button