Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have the following SQL code, but I want to check to see if the SQL user is already created before trying to run the create user code so as to avoid errors. Could someone tell me how I can do an if statement in SQL for this?

 

EXECUTE sp_detach_db @dbname = N'MRCS', 
  		     @skipchecks = N'TRUE'
GO

EXECUTE sp_attach_single_file_db @dbname   = N'MRCS', @physname = N'C:\Program Files\Ticodi\MRCS\Database\MRCS_Data.mdf'
GO

[color="Red"]If user does not exist then do this code[/color]
EXECUTE execute sp_addlogin @loginame    = N'MRCSAdmin',
    @passwd      = 'dragnet',
    @defdb       = N'MRCS',
    @deflanguage = N'us_english'
GO
[color="red"]Endif statement[/color]

 

Thanks in advance

 

Simon

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...