请教一个查询优化问题
笨狗熊 2013-03-20 11:36:46 我使用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、如果不考虑网络问题,我这个表设计和查询上是不是有什么可以优化的地方,求指教。