Evaluate in T-SQL

后端 未结 11 2200
悲&欢浪女
悲&欢浪女 2020-12-17 23:42

I\'ve got a stored procedure that allows an IN parameter specify what database to use. I then use a pre-decided table in that database for a query. The problem I\'m having i

11条回答
  •  春和景丽
    2020-12-18 00:12

    There are a few options, but they are messier than the way you are already doing. I suggest you either:
    (1) Stick with the current approach
    (2) Go ahead and embed the SQL in the code since you are doing it anyway.
    (3) Be extra careful to validate your input to avoid SQL Injection.

    Also, messiness isn't the only problem with dynamic SQL. Remember the following:
    (1) Dynamic SQL thwarts the server's ability to create a reusable execution plan.
    (2) The ExecuteSQL command breaks the ownership chain. That means the code will run in the context of the user who calls the stored procedure NOT the owner of the procedure. This might force you to open security on whatever table the statement is running against and create other security issues.

提交回复
热议问题