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)