最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

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

来源:动视网 责编:小采 时间:2020-11-09 10:03:01
文档

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

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
推荐度:
导读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


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 all
select 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 all
select 2,'分类2' union all
select 3,'分类3' union all
select 4,'分类4'

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


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

/*
id sortid1 name sortid2 name info
----------- ----------- ----- ----------- ----- -----
1 1 分类1 3 分类3 info
2 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.rortid
left join b c on a.rortid2=b.rortid

比较实用的方法

视图可以简化操作,不能提高性能。可以尝试建立索引视图

文档

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

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
推荐度:
标签: 查询 提高 数据
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top