BrianKwan
asked on
Easy query
Suppose I have a user name called "Tom" and a database called "testDB"
How can I add the user to the database by query?
I have tried "exec sp_adduser Tom, testDB", but it gives me
"[Microsoft][ODBC SQL Server Driver][SQL Server][ The Login already has
an account under a different user name".
why is it?
Brian
How can I add the user to the database by query?
I have tried "exec sp_adduser Tom, testDB", but it gives me
"[Microsoft][ODBC SQL Server Driver][SQL Server][ The Login already has
an account under a different user name".
why is it?
Brian
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You have to execute sp_adduser in the target database and supply the username and loginname.
So to go further on chigrik's answer:
use master
go
sp_addlogin 'Tom','password', 'testDB'
go
use testDB
go
sp_adduser 'Tom','Tom'
go
You may be able to skip the addlogin if it already exists...
the use database is the main issue I guess.
So to go further on chigrik's answer:
use master
go
sp_addlogin 'Tom','password', 'testDB'
go
use testDB
go
sp_adduser 'Tom','Tom'
go
You may be able to skip the addlogin if it already exists...
the use database is the main issue I guess.
If you can't see the user TOM in the database, this may result from a backup of your database from a different server. you may then use the sp_dropuser command first.
Hope this helps