问题描述
我刚刚问了一个与 SQL 相关的问题,第一个答案是:在这种情况下,动态 SQL 是必经之路."
I just asked an SQL related question, and the first answer was: "This is a situation where dynamic SQL is the way to go."
因为我之前从未听说过动态 SQL,所以我立即搜索了该站点和网络以了解它是什么.维基百科没有具有此标题的文章.第一个谷歌结果都指向用户论坛,人们在那里提出或多或少的相关问题.
As I had never heard of dynamic SQL before, I immediately searched this site and the web for what it was. Wikipedia has no article with this title. The first Google results all point to user forums where people ask more or less related questions.
但是,我没有找到动态 SQL"的明确定义.它是供应商特定的吗?我使用MySQL,但在 MySQL 手册中没有找到参考资料(在 MySQL 用户论坛中只有问题,大部分没有答案).
However, I didn't find a clear definition of what a 'dynamic SQL' is. Is it something vendor specific? I work with MySQL and I didn't find a reference in the MySQL handbook (only questions, mostly unanswered, in the MySQL user forums).
另一方面,我发现了许多对存储过程的引用.尽管我从未使用过任何存储过程,但我对什么是存储过程有了更好的了解.这两个概念有什么关系?它们是相同的东西还是一个使用另一个?
On the other hand, I found many references to stored procedures. I have a slightly better grasp of what stored procedures are, although I have never used any. How are the two concepts related? Are they the same thing or does one uses the other?
基本上,对于动态 SQL 概念的新手来说,需要做一个简单的介绍.
Basically, what is needed is a simple introduction to dynamic SQL for someone who is new to the concept.
PS:如果您愿意,您可以尝试回答我之前提出的问题:SQL:我们如何使 table1 JOIN table2 ON table1 中的字段中给定的表?
P.S.: If you feel like it, you may have a go at answering my previous question that prompted this one: SQL: How can we make a table1 JOIN table2 ON a table given in a field in table1?
推荐答案
Dynamic SQL 只是即时构建查询的地方 - 对于某些供应商,您可以构建查询的文本在一个存储过程中进行动态查询,然后执行生成的 SQL.在其他情况下,该术语仅指由代码对客户端做出的决定(这至少是供应商中立的)
Dynamic SQL is merely where the query has been built on the fly - with some vendors, you can build up the text of the dynamic query within one stored procedure, and then execute the generated SQL. In other cases, the term merely refers to a decision made by code on the client (this is at least vendor neutral)
这篇关于什么是动态 SQL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!