Use database inside a stored procedure

后端 未结 7 1413
故里飘歌
故里飘歌 2020-12-10 10:30

I need to make a stored procedure which creates a user in more than one database. Something like this:

USE [database1]

CREATE USER [userLogin] FOR LOGIN [us         


        
7条回答
  •  失恋的感觉
    2020-12-10 11:07

    It should be noted that if you want to use single quotes within a EXEC command, you will need to double the amount of single quotes

    e.g.

    EXEC ('USE [database1]; select * from Authors where name = ''John'' ')
    

    In this example, John has 2 single quotes before and after it. You cannot use double quotes for this type of query.

提交回复
热议问题