Where your parameters are always Data Items, both when being passed to the StoredProc and when used in yor DynamicSQL, everything will stay safe.
Should any of your StoredProc s parameters end up being table or field names, and so forming part of the structure of the DynamicSQL itself, you introduce a new risk : That the parameter can be used to inject rogue SQL Code.
- To prevent against such an injection attack you should always validate any such parameters.
如何做到这一点的一个例子是,将投入参数作为标语,而不是直接代之于动态SQL...。
SET @SQL = @SLQ + CASE targetTable WHEN 1 THEN table1
WHEN tx THEN tableX
END
Some people suggest you only need to validate on the client application. But that means that if someone becomes able to execute you SP s directly, the SP has become a point of attack. I always prefer to validate both on the client AND in the server.
www.un.org/Depts/DGACM/index_spanish.htm
http://www.ohchr.org。 业绩
Note that using DynamicSQL isn t always a guarnatee of performance increases. If you use parameterised queries, the execution plans can indeed be stored. But if the queries do vary greatly, you may still find a significant overhead in compiling the SQL.
还有事实是,依赖性跟踪损失了。 不可能看看SP所依赖的是什么表格,因为该代码被掩盖为示意图。
我很少发现需要有动态的SQL。 往往随着若干选择的问询,可以改革复杂的问题。 或者可以调整数据,以满足新的需求。 或者甚至通过数据重新思考数据和算法。 甚至可以suggest,取决于动态SQL是另一个根本问题的一个指标。
Perhaps it s not in the scope of your question, but it would be interesting to see the actual puzzle you re facing; to see if anyone has any alternative approaches for you.