Re: Finding out if a login exists
From: alien2_51 (dan.billow"at"n.o.s.p.a.m.monacocoach.commercialversion)
Date: 09/22/04
- Next message: PVR: "How to move from developer to DBA"
- Previous message: Aaron [SQL Server MVP]: "Re: Need help: The tables I create are system tables; why not user tables?"
- In reply to: Carlos Galavis: "Finding out if a login exists"
- Next in thread: Alejandro Mesa: "RE: Finding out if a login exists"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 22 Sep 2004 11:05:00 -0700
if not exists (select * from master.dbo.syslogins where loginname =
N'AppLinkUser')
BEGIN
declare @logindb nvarchar(132), @loginlang nvarchar(132) select @logindb =
N'Intergy', @loginlang = N'us_english'
if @logindb is null or not exists (select * from master.dbo.sysdatabases
where name = @logindb)
select @logindb = N'master'
if @loginlang is null or (not exists (select * from master.dbo.syslanguages
where name = @loginlang) and @loginlang <> N'us_english')
select @loginlang = @@language
exec sp_addlogin N'AppLinkUser', null, @logindb, @loginlang
END
GO
You can generate this code from All Tasks>Generate SQL option option in EM,
look at options and select script logins...
"Carlos Galavis" <cgalavis> wrote in message
news:uOE1RtMoEHA.3488@TK2MSFTNGP12.phx.gbl...
> Hi,
> I need to write a SQL script to create a login in SQLServer and assigned
> some permissions to certain tables. I am using then "sp_grantlogin" stored
> procedure to create the login, but if the login happens to exist, the
script
> fails with an error. I need to be able to determine if the login already
> exists and call this stored procedure only in the cases in which it
doesn't.
>
> Thanks,
>
> -Carlos
>
>
- Next message: PVR: "How to move from developer to DBA"
- Previous message: Aaron [SQL Server MVP]: "Re: Need help: The tables I create are system tables; why not user tables?"
- In reply to: Carlos Galavis: "Finding out if a login exists"
- Next in thread: Alejandro Mesa: "RE: Finding out if a login exists"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|