• <i id='IGJZS'><tr id='IGJZS'><dt id='IGJZS'><q id='IGJZS'><span id='IGJZS'><b id='IGJZS'><form id='IGJZS'><ins id='IGJZS'></ins><ul id='IGJZS'></ul><sub id='IGJZS'></sub></form><legend id='IGJZS'></legend><bdo id='IGJZS'><pre id='IGJZS'><center id='IGJZS'></center></pre></bdo></b><th id='IGJZS'></th></span></q></dt></tr></i><div id='IGJZS'><tfoot id='IGJZS'></tfoot><dl id='IGJZS'><fieldset id='IGJZS'></fieldset></dl></div>
  • <small id='IGJZS'></small><noframes id='IGJZS'>

    <tfoot id='IGJZS'></tfoot>

      • <bdo id='IGJZS'></bdo><ul id='IGJZS'></ul>

        <legend id='IGJZS'><style id='IGJZS'><dir id='IGJZS'><q id='IGJZS'></q></dir></style></legend>

        使用 UNION 运算符在 SQL 视图上创建索引?它真的会提高性能吗?

        时间:2024-04-15

          <legend id='PybrM'><style id='PybrM'><dir id='PybrM'><q id='PybrM'></q></dir></style></legend>

        • <tfoot id='PybrM'></tfoot>
              <i id='PybrM'><tr id='PybrM'><dt id='PybrM'><q id='PybrM'><span id='PybrM'><b id='PybrM'><form id='PybrM'><ins id='PybrM'></ins><ul id='PybrM'></ul><sub id='PybrM'></sub></form><legend id='PybrM'></legend><bdo id='PybrM'><pre id='PybrM'><center id='PybrM'></center></pre></bdo></b><th id='PybrM'></th></span></q></dt></tr></i><div id='PybrM'><tfoot id='PybrM'></tfoot><dl id='PybrM'><fieldset id='PybrM'></fieldset></dl></div>
              • <bdo id='PybrM'></bdo><ul id='PybrM'></ul>
                  <tbody id='PybrM'></tbody>

                <small id='PybrM'></small><noframes id='PybrM'>

                  本文介绍了使用 UNION 运算符在 SQL 视图上创建索引?它真的会提高性能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试在以下视图上创建索引:

                  I am trying to create an index on the following view:

                  SELECT     'Candidate' AS Source, CandidateID AS SourceId, LastName + ', ' + FirstName AS SourceName
                  FROM         dbo.Candidates
                  UNION
                  SELECT     'Resource' AS Source, ResourceID AS SourceId, LastName + ', ' + FirstName AS SourceName
                  FROM         dbo.Resources
                  UNION
                  SELECT     'Deal' AS Source, DealID AS SourceId, CONVERT(varchar, Number) + '-' + CONVERT(varchar, RevisionNumber) AS SourceName
                  FROM         dbo.Deals
                  UNION
                  SELECT     'Job Order' AS Source, JobOrderID AS SourceId, CustomerNumber AS SourceName
                  FROM         dbo.JobOrders
                  

                  我收到以下错误:

                  Msg 1939, Level 16, State 1, Line 2
                  Cannot create index on view '_Source' because the view is not schema bound.
                  

                  我将 WITH SCHEMABINDING 添加到 CREATE 中,现在出现以下错误:

                  I added WITH SCHEMABINDING to the CREATE and now get the following error:

                  Msg 10116, Level 16, State 1, Line 2
                  Cannot create index on view 'DEALMAKER.dbo._Source' because it contains one or more UNION, INTERSECT, or EXCEPT operators. Consider creating a separate indexed view for each query that is an input to the UNION, INTERSECT, or EXCEPT operators of the original view.
                  

                  我的问题是:

                  我将如何在此视图上创建索引?创建单独的索引视图真的有用吗?

                  How would I create an index on this view? Would creating separate indexed views really work?

                  最后,对于可能加入此视图的任何查询,我是否真的会看到性能改进?

                  Lastly, am I really going to see a performance improvement for any queries that may JOIN this view?

                  提前致谢!

                  推荐答案

                  不能在使用联合运算符的视图上创建索引.实在不行,抱歉!

                  You cannot create an index on a view that makes use of a union operator. Really no way around that, sorry!

                  我想你已经看过了,但请查看这个 MSDN 页面.它给出了索引视图的要求,并解释了它们是什么以及它们是如何工作的.

                  I would imagine you've seen this, but check out this MSDN page. It gives the requirements for indexed views and explains what they are and how they work.

                  至于如果您可以对视图进行索引,您是否会看到性能优势,这完全取决于您的表的大小.我不希望对创建单独的索引视图有任何影响,因为我假设您的表已经被索引并且您没有在视图中执行任何连接或逻辑.

                  As to whether or not you'd see a performance benefit if you COULD index the view, that would depend entirely on the size of your tables. I would not expect any impact on creating separate indexed views, as I would assume that your tables are already indexed and you aren't doing any joining or logic in the view.

                  这篇关于使用 UNION 运算符在 SQL 视图上创建索引?它真的会提高性能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 mysql 中为视图创建注释 下一篇:创建一个带有 num_rows 列的视图 - MySQL

                  相关文章

                  1. <tfoot id='t9BvQ'></tfoot>

                    <small id='t9BvQ'></small><noframes id='t9BvQ'>

                      <bdo id='t9BvQ'></bdo><ul id='t9BvQ'></ul>
                    <legend id='t9BvQ'><style id='t9BvQ'><dir id='t9BvQ'><q id='t9BvQ'></q></dir></style></legend>
                    1. <i id='t9BvQ'><tr id='t9BvQ'><dt id='t9BvQ'><q id='t9BvQ'><span id='t9BvQ'><b id='t9BvQ'><form id='t9BvQ'><ins id='t9BvQ'></ins><ul id='t9BvQ'></ul><sub id='t9BvQ'></sub></form><legend id='t9BvQ'></legend><bdo id='t9BvQ'><pre id='t9BvQ'><center id='t9BvQ'></center></pre></bdo></b><th id='t9BvQ'></th></span></q></dt></tr></i><div id='t9BvQ'><tfoot id='t9BvQ'></tfoot><dl id='t9BvQ'><fieldset id='t9BvQ'></fieldset></dl></div>