请教一个查询优化问题
我使用MS-SQL 2008 建了如下两表:
if exists (select 1
from sysobjects
where id = object_id('T_CANVERSION')
and type = 'U')
drop table T_CANVERSION
go
/*==============================================================*/
/* Table: T_CANVERSION */
/*==============================================================*/
create table T_CANVERSION (
versionID int identity
constraint CKC_VERSIONID_T_CANVER check (versionID >= 1),
versionName varchar(30) not null,
groupID char(9) not null,
carType int not null,
constraint PK_T_CANVERSION primary key (versionID)
)
go
if exists (select 1
from sysobjects
where id = object_id('T_CANDATA')
and type = 'U')
drop table T_CANDATA
go
/*==============================================================*/
/* Table: T_CANDATA */
/*==============================================================*/
create table T_CANDATA (
intID int identity
constraint CKC_INTID_T_CANDAT check (intID >= 0),
strCtrlorName varchar(50) not null,
strCanID varchar(20) not null,
intOperate int not null,
intStByte int not null,
intLenByte int not null,
intStBit int not null,
intLenBit int not null,
flPer varchar(12) not null,
intOffset int not null,
intSetEn int not null,
intGroup int not null,
intCtrlType int not null,
inTime varchar(20) not null,
versionID int not null,
constraint PK_T_CANDATA primary key (intID)
)
go
alter table T_CANDATA
add constraint FK_T_CANDAT_REFERENCE_T_CANVER foreign key (versionID)
references T_CANVERSION (versionID)
go
建完表后在T_CANVERSION插入几条数据,在T_CANDATA插入几百条数据。
然后运行如下查询语句:
select intID, strCtrlorName, strCanID, intOperate, intStByte, intLenByte, intStBit, intLenBit, flPer, intOffset, intSetEn, intGroup, inTime, intCtrlType, versionID from T_CANDATA
就总是在查出部分数据后报如下错误:
消息 64,级别 20,状态 0,第 0 行
在从服务器接收结果时发生传输级错误。 (provider: TCP 提供程序, error: 0 - 指定的网络名不再可用。)
特别说明:
1、数据库是在外网的服务器上,通过远程连接进行数据查询。
2、我在家远程连接查询很快就把数据查出来了,在公司远程查询就报上面描述的错误。我想过可能是网络限制问题,但是这个表才只有几百条数据,公司上网路由器限制每秒最大流量有180K/S,这么点数据不应该查不出来啊,不知道为什么。
3、如果不考虑网络问题,我这个表设计和查询上是不是有什么可以优化的地方,求指教。
if exists (select 1
from sysobjects
where id = object_id('T_CANVERSION')
and type = 'U')
drop table T_CANVERSION
go
/*==============================================================*/
/* Table: T_CANVERSION */
/*==============================================================*/
create table T_CANVERSION (
versionID int identity
constraint CKC_VERSIONID_T_CANVER check (versionID >= 1),
versionName varchar(30) not null,
groupID char(9) not null,
carType int not null,
constraint PK_T_CANVERSION primary key (versionID)
)
go
if exists (select 1
from sysobjects
where id = object_id('T_CANDATA')
and type = 'U')
drop table T_CANDATA
go
/*==============================================================*/
/* Table: T_CANDATA */
/*==============================================================*/
create table T_CANDATA (
intID int identity
constraint CKC_INTID_T_CANDAT check (intID >= 0),
strCtrlorName varchar(50) not null,
strCanID varchar(20) not null,
intOperate int not null,
intStByte int not null,
intLenByte int not null,
intStBit int not null,
intLenBit int not null,
flPer varchar(12) not null,
intOffset int not null,
intSetEn int not null,
intGroup int not null,
intCtrlType int not null,
inTime varchar(20) not null,
versionID int not null,
constraint PK_T_CANDATA primary key (intID)
)
go
alter table T_CANDATA
add constraint FK_T_CANDAT_REFERENCE_T_CANVER foreign key (versionID)
references T_CANVERSION (versionID)
go
建完表后在T_CANVERSION插入几条数据,在T_CANDATA插入几百条数据。
然后运行如下查询语句:
select intID, strCtrlorName, strCanID, intOperate, intStByte, intLenByte, intStBit, intLenBit, flPer, intOffset, intSetEn, intGroup, inTime, intCtrlType, versionID from T_CANDATA
就总是在查出部分数据后报如下错误:
消息 64,级别 20,状态 0,第 0 行
在从服务器接收结果时发生传输级错误。 (provider: TCP 提供程序, error: 0 - 指定的网络名不再可用。)
特别说明:
1、数据库是在外网的服务器上,通过远程连接进行数据查询。
2、我在家远程连接查询很快就把数据查出来了,在公司远程查询就报上面描述的错误。我想过可能是网络限制问题,但是这个表才只有几百条数据,公司上网路由器限制每秒最大流量有180K/S,这么点数据不应该查不出来啊,不知道为什么。
3、如果不考虑网络问题,我这个表设计和查询上是不是有什么可以优化的地方,求指教。
...全文
相关推荐
数据结构课程设计公交线路优化查询问题报告+代码C++代码
具体来说,我们需要处理三个主要的优化查询问题:最省钱路径查询、最省时路径查询以及考虑等车时间的最省时路径查询。#### 基本要求概述1.
mysql in语句子查询效率慢的优化技巧示例
这种做法看似合理,但当子查询返回的结果集较大时,性能问题就显现出来。一个常见的优化方法是使用临时表或子查询别名。
一个20秒SQL慢查询优化的经历与处理方案
在这个关于"一个20秒SQL慢查询优化的经历与处理方案"的文章中,作者分享了在项目上线过程中遇到的一个性能瓶颈。问题起因于一个SQL查询执行时间过长,长达20多秒,导致接口调用超时,影响了页面数据的正
数据库查询优化之子查询优化
在数据库查询优化中,子查询优化是一项关键技能,尤其是在处理大数据集和复杂查询时。本文以一个具体的案例来探讨如何优化查询效率。问题在于获取所有不是掌门人的员工,并按照他们的年龄进行分组,原始SQL如下:
SQL order by ID desc/asc加一个排序的字段解决查询慢问题
在给定的问题中,"SQL order by ID desc/asc加一个排序的字段解决查询慢问题"是一个常见的数据库优化技巧。


