22,209
社区成员
发帖
与我相关
我的任务
分享
分区视图
分区视图是提高查询性能的一个很好的办法
--看下面的示例
--示例表
create table tempdb.dbo.t_10(
id int primary key check(id between 1 and 10),name varchar(10))
create table pubs.dbo.t_20(
id int primary key check(id between 11 and 20),name varchar(10))
create table northwind.dbo.t_30(
id int primary key check(id between 21 and 30),name varchar(10))
go
--分区视图
create view v_t
as
select * from tempdb.dbo.t_10
union all
select * from pubs.dbo.t_20
union all
select * from northwind.dbo.t_30
go
--插入数据
insert v_t select 1 ,'aa'
union all select 2 ,'bb'
union all select 11,'cc'
union all select 12,'dd'
union all select 21,'ee'
union all select 22,'ff'
--更新数据
update v_t set name=name+'_更新' where right(id,1)=1
--删除测试
delete from v_t where right(id,1)=2
--显示结果
select * from v_t
go
--删除测试
drop table northwind.dbo.t_30,pubs.dbo.t_20,tempdb.dbo.t_10
drop view v_t
/**//*--测试结果
id name
----------- ----------
1 aa_更新
11 cc_更新
21 ee_更新
(所影响的行数为 3 行)
==*/