Bulk insert... 方式导入30w数据到数据库表中
导入Excel文件到数据表
1) 使用逐行读取Excel文件记录的方式,记录多了速度会很慢
2) 使用 bulk insert testdb.dbo.employeesB from 'c:\temp\employeesC.csv'
3) EMS Advanced Data Import/ EMS Advanced Data Export
employees,为MySQL中的数据表,转到MSSQL中作为例子数据,为不破坏数据库 testdb中的数据表,复制了employeesB做试验
//下面是以Bulk insert的方式


//按钮中的事件很普通的用法,就是对bulk insert...的应用(当然里面的文件也可写成选择文件的方式,替换掉固定的文件名):
procedure TForm1.BitBtn1Click(Sender: TObject);
var
strPath ,strFile:String;
strsql:String;
strCond:String;
str_sum:String;
begin
OpenDialog1.FileName:='*.csv';
// if not OpenDialog1.Execute then
// begin
// Exit;
// end;
// if ExtractFileExt(OpenDialog1.FileName) <> '.csv' then
// begin
// MessageBox(0, '请选择正确的excel文件',PChar('提示'),MB_OK or MB_ICONWARNING);
// Exit;
// end;
if OpenDialog1.Execute then
begin
//strCond := ExtractFiledir(opendialog1.FileName);
strPath := ExtractFilePath(Application.ExeName)+'employeesC.csv';
//strFile := ExtractFiledir(opendialog1.FileName);
strsql := 'bulk insert testdb.dbo.employeesB from '''+strPath+''' ';
with DM.ADOQuery2 do
begin
close;
sql.clear;
sql.add(strsql);
ExecSQL;
end;
end;
end;
//


OnionYang@
浙公网安备 33010602011771号