with DataModule1.SQuery do
begin
//DisableControls;
First;
while not eof do
begin
Edit;
FieldByName('sno').asInteger:= RecNo;
post;
Next;
end;
updateBatch;
//EnableControls;
end;
报错:违反关键约束!!
应该怎么办?
begin
//DisableControls;
First;
while not eof do
begin
Edit;
FieldByName('sno').asInteger:= RecNo;
post;
Next;
end;
updateBatch;
//EnableControls;
end;
报错:违反关键约束!!
应该怎么办?
如果使用 MS SQL SERVER,考虑增加一个自动增长的字段来处理。
首先将要改的全部update成不重复的如:-1*N;N + 100000
然后在update成你想要的,土吧!
本来我想这样的(就是注释了的二行出错),有没有人有更好的办法??????:
t:= GetTickCount;
i:= 0;
tmpquery.SQL.Text:='alter table song drop constraint PK_Song';
tmpquery.ExecSQL;
First;
while not eof do
begin
Edit;
i:= i+1;
FieldByName('songno').asString:= FillStrHead(IntToStr(i),'0',5);
Next;
end;
updateBatch;
//tmpquery.SQL.Text:='alter table song add constraint PK_Song primary key (songno)';
//tmpquery.ExecSQL;
t:= GetTickCount - t;
showmessage(inttostr(t));
SQL server有没有这样的语句,我记得oracle有!:ALTER TABLE xxx disable constraint xxx primary key;
1.问题的造成相信大家知道了,就是constraint报错,我的方法虽然土增加了一个Update,但是由于可以采用Update语句而不用明细循环更新,因此仅仅增加一条update语句,效率不会低到哪里去,这是肯定的。
2.alter table 语句应当少用,这是真心话,特别是在程序中应当禁止,原因有两个:alter table 截断事务,自动提交;主键没有了后用ado进行更新会造成update失败(如果没有其他索引的话)