How to execute store procedure for another DB?

后端 未结 3 347
野趣味
野趣味 2021-01-18 02:15

I have a stored procedure that should be able to be executed on any table of any database on my MS Sql Server. Most of the combination of EXEC and USE statements didn\'t res

3条回答
  •  清歌不尽
    2021-01-18 03:18

    You can fully qualify both tables and stored procedures. In other words you can do this:

    UPDATE [OtherDB].[Schema].[targetTable] SET ...
    

    It appears you are doing this in your proc already.

    You can also EXEC a stored procedure using the Fully Qualified name - e.g.

    EXEC [OtherDB].[dbo].[usp_TrimAndLowerCaseVarcharFields]
    

    Honestly, your proc looks fine, are you receiving any error messages? If so please post them. Also, make sure your user has access to the other DB.

提交回复
热议问题