php mysql 建立索引檢視表執行個體教程

來源:互聯網
上載者:User

述前說明:
CREATE VIEW 語句時,ANSI_NULLS 和 QUOTED_IDENTIFIER 選項必須設定為 ON。OBJECTPROPERTY 函數通過 ExecIsAnsiNullsOn 或 ExecIsQuotedIdentOn 屬性為視圖報告此資訊

表a,欄位a1,a2
表b,欄位b1,b2
要弄個視圖union all兩個表

$sql ='CREATE VIEW dbo.VIEW2
  AS
  SELECT * FROM a
  UNION ALL
  (SELECT * FROM b )';
  

上面的是簡單的建立視圖並沒有索引下面我們來看看關於建立索引檢視表

對指定表或指定表的視圖建立關係索引。可在向表中填入資料前建立索引。可通過指定限定的資料庫教程名稱對另一個資料庫中的表或視圖建立關係索引。
文法:

CREATE [ UNIQUE ] [ CLUSTERED | NONCLUSTERED ] INDEX index_name
    ON <object> ( column_name [ ASC | DESC ] [ ,...n ] )
    [ WITH <backward_compatible_index_option> [ ,...n ] ]
    [ ON { filegroup_name | "default" } ]

<object> ::=
{
    [ database_name. [ owner_name ] . | owner_name. ]
        table_or_view_name
}

<backward_compatible_index_option> ::=
{
    PAD_INDEX
  | FILLFACTOR = fillfactor
  | SORT_IN_TEMPDB
  | IGNORE_DUP_KEY
  | STATISTICS_NORECOMPUTE
  | DROP_EXISTING
}


//--建立視圖  
  create   view   v  
  with   schemabinding  
  as  
  select   ID,name   from   dbo.A  
  go  
   
//  --建立索引  
  create   unique   clustered   index   v_index   on   v(ID)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.