SQLServer2000版本和SQLServer2015操作还不一样
SQLServer2000数据库操作方法
公司的数据库创建有点问题,原数据创建和建立索引命令如下
--创建数据库带主键
create table TestReport(
TeleName char(4) not null,
AnalogType int not null,
AnalogNo int not null,
AnalogName char(50) not null,
StatDate int not null,
TestValue float not null,
TestTime int not null,
constraint PK_TESTREPORT Primary Key (TeleName,AnalogType,AnalogNo,StatDate));
--创建索引
/*==============================================================*/
/* Index: DayReport_Index */
/*==============================================================*/
create unique index DayReport_Index on DayReport (
TeleName ,
AnalogType ,
AnalogNo ,
StatDate
);
将数据有问题部分处理:
use csm2010;
--先删除主键,然后再创建主键
alter table TestReport drop constraint PK_TESTREPORT;
alter table TestReport add constraint PK_TestReport Primary Key(TeleName,AnalogType,AnalogNo,TestTime);
--先删除索引,再创建索引
drop index TestReport.TestReport_Index;
create unique index TestReport_Index on TestReport(TeleName ,AnalogType ,AnalogNo ,TestTime );
我在SQLServer2015上实验都成功,但是拷贝到SQLServer2000虚拟机上实验就不行了
准确的讲,这里是现场方法,以前的方法是古老方法
alter table TestReport drop constraint PK_TESTREPORT;
alter table TestReport add constraint PK_TestReport Primary Key(TeleName,AnalogType,AnalogNo,TestTime);
drop index TestReport_Index on TestReport;
create unique index TestReport_Index on TestReport (TeleName ,AnalogType ,AnalogNo ,TestTime );
我将以上命令写了个批处理脚本,方便客户操作
updateTestReport.cmd
osql /d CSM2010 -E -i updateTestReprot.sql
pause
updateTestReprot.sql
use csm2010;
--先删除主键,然后再创建主键
alter table TestReport drop constraint PK_TESTREPORT;
alter table TestReport add constraint PK_TestReport Primary Key(TeleName,AnalogType,AnalogNo,TestTime);
--先删除索引,再创建索引
drop index TestReport.TestReport_Index; --此处不同于SQLServer2015操作
create unique index TestReport_Index on TestReport(TeleName ,AnalogType ,AnalogNo ,TestTime );