mssql 如何提高数据库关联查询性能

mssql 怎么样加强数据库教程关联合检查询品质

— 测量检验数据:[a1]if object_id(‘[a1]’) is not null drop table
[a1]create table [澳门新葡新京 ,a1]([id] int,[sortid1] int,[sortid2]
int,[info] varchar(5))insert [a1]select 1,1,3,’info’ union allselect
2,2,4,’info2′

— 测验数据:[b2]if object_id(‘[b2]’) is not null drop table
[b2]create table [b2]([sortid] int,[name] varchar(5))insert
[b2]select 1,’分类1′ union allselect 2,’分类2′ union allselect
3,’分类3′ union allselect 4,’分类4′

select * from [a1]select * from [b2]

select a1.id,sortid1,b2.name,a1.sortid2,b.name,a1.[info]from
dbo.a1left join b2 on a1.sortid1 = b2.sortidleft join b2 b on a1.sortid2
= b.sortid

/*id sortid1 name sortid2 name info———– ———– —–
———– —– —–1 1 分类1 3 分类3 info2 2 分类2 4 分类4 info2

(2 行受影响卡塔尔(قطر‎*/

本来方法

select id,rortid1,b.name as name1 , sortid2,c.name as name2,info from a
left join b on a.rortid1=b.rortidleft join b c on a.rortid2=b.rortid

比较实用的章程

视图能够简化操作,无法增高质量。可以品尝创建索引视图

相关文章