January 10, 2012 at 7:40 am
How do I get it NOT to error out if login already exists?
IF NOT EXISTS(SELECT principal_id FROM sys.database_principals WHERE name = '[mylogin]')
BEGIN
CREATE USER [mylogin] FOR LOGIN [mylogin]
END
January 10, 2012 at 7:52 am
Script out a user from SSMS window, you will find necessary options in it.
January 10, 2012 at 8:19 am
Don't enclose the user name in square brackets:
IF NOT EXISTS(SELECT principal_id FROM sys.database_principals WHERE name = 'mylogin')
BEGIN
CREATE USER [mylogin] FOR LOGIN [mylogin]
END
-- Gianluca Sartori
January 11, 2012 at 5:05 am
Yes, it was the brackets. Thank you!
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply