Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create User from a different DB in SQL Server

Is there any way I can create a user on a database from the master DB(or any other DB)

IF EXISTS (SELECT 1 FROM   j_test.sys.database_principals WHERE  name = N'test_user') 
  DROP USER j_test.[test_user]; --doesnt't work.
like image 483
need_the_buzz Avatar asked Aug 24 '26 01:08

need_the_buzz


1 Answers

You either need to change the context to that database or dynamically go there:

EXEC j_test..sp_executesql N'DROP USER test_user;';
like image 132
Aaron Bertrand Avatar answered Aug 26 '26 18:08

Aaron Bertrand



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!