首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

请问一个查询优化有关问题

2013-03-22 
请教一个查询优化问题我使用MS-SQL 2008 建了如下两表:if exists (select 1fromsysobjectswhereid objec

请教一个查询优化问题
我使用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、如果不考虑网络问题,我这个表设计和查询上是不是有什么可以优化的地方,求指教。
[解决办法]
单表无条件查询,没的优化
公司是否有防火墙限制?

[解决办法]
根据你的描述,可能是返回的结果过大,导致达到了带宽上线,堵死了。然后就中断连接。你有试过把数据另存为txt,有多大吗?
[解决办法]
云数据库?联系他们管理员让协助查询,在服务器端监控连接与断开的情况。这个报错是在查询时被强制IP隔离会出现的。

热点排行