lidds Posted June 17, 2007 Posted June 17, 2007 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 Quote
Administrators PlausiblyDamp Posted June 18, 2007 Administrators Posted June 18, 2007 Could you not just check the sysusers table to see if the name already exists? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.