Create users dynamic names and assgin roles

前端 未结 2 1893
情话喂你
情话喂你 2020-12-11 19:56

I need to create user with dynamic names with a variable name

example :

The following code gives a syntax error.

Create Log         


        
2条回答
  •  旧时难觅i
    2020-12-11 20:11

    You cannot use variables for object names. You can cheat

    exec sp_addlogin @User_name, @password;
    

    Either that or construct dynamic SQL, but make sure to use QUOTENAME to prevent SQL injection.

提交回复
热议问题