述前说明:
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)