目的:将download数据库中card,cardType,customer表导入test数据库card,cardType,customer表。导入之前将test数据库card,cardType,customer清空 download数据库中card,cardType,customer表中都有记录。
第一步,清空test数据库中card,cardType,customer记录 sqlStatement.close;
sqlStatement.SQL.Clear;
sqlStatement.SQL.Add('delete from card');
sqlStatement.ExecSQL ;
sqlStatement.close;
sqlStatement.SQL.Clear;
sqlStatement.SQL.Add('delete from cardType');
sqlStatement.ExecSQL ;
sqlStatement.close;
sqlStatement.SQL.Clear;
sqlStatement.SQL.Add('delete from customer');
sqlStatement.ExecSQL ;
第二步,将download数据库中card,cardType,customer插入test数据库中card,cardType,customer表。arg1:='insert into test.card select * from download.card';
arg2:='insert into test.cardType select * from download.cardType';
arg3:='insert into test.customer select * from download.customer';
sqlStatement.Close;
sqlStatement.SQL.Clear;
sqlStatement.SQL.Add(arg1);
sqlStatement.ExecSQL ; sqlStatement.Close;
sqlStatement.SQL.Clear;
sqlStatement.SQL.Add(arg2);
sqlStatement.ExecSQL ; sqlStatement.Close;
sqlStatement.SQL.Clear;
sqlStatement.SQL.Add(arg3);
sqlStatement.ExecSQL ;
运行5次,发现test数据库中的customer表有3次没有成功插入记录,表中无记录.但是,card,cardType表每次都成功插入记录。是什么原因呢?
第一步,清空test数据库中card,cardType,customer记录 sqlStatement.close;
sqlStatement.SQL.Clear;
sqlStatement.SQL.Add('delete from card');
sqlStatement.ExecSQL ;
sqlStatement.close;
sqlStatement.SQL.Clear;
sqlStatement.SQL.Add('delete from cardType');
sqlStatement.ExecSQL ;
sqlStatement.close;
sqlStatement.SQL.Clear;
sqlStatement.SQL.Add('delete from customer');
sqlStatement.ExecSQL ;
第二步,将download数据库中card,cardType,customer插入test数据库中card,cardType,customer表。arg1:='insert into test.card select * from download.card';
arg2:='insert into test.cardType select * from download.cardType';
arg3:='insert into test.customer select * from download.customer';
sqlStatement.Close;
sqlStatement.SQL.Clear;
sqlStatement.SQL.Add(arg1);
sqlStatement.ExecSQL ; sqlStatement.Close;
sqlStatement.SQL.Clear;
sqlStatement.SQL.Add(arg2);
sqlStatement.ExecSQL ; sqlStatement.Close;
sqlStatement.SQL.Clear;
sqlStatement.SQL.Add(arg3);
sqlStatement.ExecSQL ;
运行5次,发现test数据库中的customer表有3次没有成功插入记录,表中无记录.但是,card,cardType表每次都成功插入记录。是什么原因呢?
另一种方法就是把表彻底删掉(drop table).然后(insert into)会自动根据download的表的字段生成一个新表的,这个方法一般不会出错的。