SQL Server 通配符
考虑到存储过程是编译的代码单元?
Does Select * from <table/view>
have the same performance implication regarding wildcard interpretation when used in a dynamic T-SQL statement as against using it in a stored procedure, given that the stored procedure is a compiled unit of code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要回答你的问题,需要稍微拆开一下:
SELECT *
有 3 种主要缺点:我不确定你所说的“关于通配符解释的含义”是什么意思,但我怀疑你误解了为什么 SELECT * 是一个坏主意 - SQL 引擎无论如何都会验证提供的列; “扩展”通配符的成本本质上是0。
存储过程实际上并不是“代码的编译单元”:存储过程的查询计划通常会在首次运行后被缓存,但实际上也是如此在许多/大多数情况下也可以使用 hoc SQL 语句。
现在,真正回答您的问题:是,在即席 SQL 中使用
SELECT *
的任何缺点也同样适用于存储过程内的 SQL。To answer your question, it needs to be picked apart a little:
SELECT *
has 3 main types of disadvantages:I'm not sure what you mean by "implication regarding wildcard interpretation", but I suspect you're misunderstanding why SELECT * is a bad idea - the SQL engine validates provided columns anyway; the cost of "expanding" the wildcard is essentially 0.
A stored procedure is not really a "compiled unit of code": the query plan for a stored procedure will usually be cached after it first runs, but the same is actually true of ad-hoc SQL statements also in many/most circumstances.
Now, to actually answer your question: Yes, any disadvantages of using
SELECT *
in ad-hoc SQL also apply, equally, to SQL inside of a stored procedure.