August 28, 2007 at 9:20 am
Hi
I want to create a new sql user through T-SQL but i need to be sure that he doesn't exists.
How i checked if user exists?
Thanks'
Ido
August 28, 2007 at 9:42 am
User or login ?
In case of former you can query sys.sysusers in your database and map it to existing login with sp_grantdbaccess, in case of latter you can query master.sys.syslogins; in either case ...Where name = <your_user_login_name>
August 28, 2007 at 1:03 pm
Hi
That exactly what i need, thanks.
by the way, you know how to grant db_owner to user in specific database by way of TSQL?
Thanks again
Ido
August 28, 2007 at 3:04 pm
EXEC sp_addrolemember N'db_owner', N'login_name'
August 28, 2007 at 9:42 pm
Thanks Again
it is very helpful.
Ido
March 31, 2010 at 1:08 pm
Hello
I shall highly appreciate if you please help me and give me the correct syntax
I would like to check whether a user (test2) is present in a database and then delete.
Use ABC <database name>
if exists (select * from dbo.sysobjects where id = object_id(N'[test2]') and OBJECTPROPERTY(id, N'IsUser') = 1)
drop user test2
GO
March 31, 2010 at 8:28 pm
sysobjects view does not contain users. Use this script:
if exists (select * from sys.sysusers where name='test2')
drop user test2
GO
March 31, 2010 at 11:10 pm
You should be checking sys.database_principals to see if the user exists or not.
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
March 31, 2010 at 11:14 pm
double post
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
Viewing 9 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy