PHP MySQL Create an indexed view instance tutorial

Source: Internet
Author: User

Before the statement:
CREATE VIEW Statement, the ANSI_NULLS and QUOTED_IDENTIFIER options must be set to ON. The OBJECTPROPERTY function reports this information to the view through the Execisansinullson or Execisquotedidenton properties

Table A, field A1,A2
Table B, Field b1,b2
To get a view union all two tables

$sql = ' CREATE VIEW dbo. VIEW2
As
SELECT * from a
UNION All
(SELECT * from B) ';

The above is a simple create view and no index below let's see about creating an indexed view

Creates a relational index on a view of a specified table or a specified table. Indexes can be created before the data is filled in to the table. You can create a relational index on a table or view in another database by specifying a qualified database tutorial name.
Grammar:

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 a view
Create VIEW V
With schemabinding
As
Select Id,name from dbo. A
Go

--Create an index
Create unique clustered index V_index on V (ID)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.