ACCESS 一次性插入多條資料

2021-07-24 06:44:53 字數 1475 閱讀 6837

在access的查詢中,通常一次只能插入一條記錄,如果同時有多條記錄要追加,就要寫多個查詢,這有點麻煩。能不能在乙個查詢中實現多條記錄的追加呢?經多方查詢與測試,發現可以用以下方法實現,現分享給大家。

insert into students

select distinctrow *

from (select 1 as id,"張三" as xm,"男" as xb,"12" as bj from msysobjects union

select 2 as id,"李四" as xm,"女" as xb,"13" as bj from msysobjects union

select 3 as id,"王五" as xm,"女" as xb,"14" as bj from msysobjects union

select 4 as id,"趙六" as xm,"男" as xb,"15" as bj from msysobjects union

select 5 as id,"孫七" as xm,"女" as xb,"16" as bj from msysobjects union

select 6 as id,"吳八" as xm,"男" as xb,"17" as bj from msysobjects)  as temp;

說明:此處的 students 是乙個表,欄位有:id,xm,xb,bj。msysobjects 是系統表,只要建立物件,此表中就一定有記錄,此表也可以用其它表代替,不過要保證表中至少有一條記錄,至於記錄的內容在此無關緊要。

另一寫法:

insert into students

select *

from (select top 1 1 as id,"張三" as xm,"男" as xb,"12" as bj from msysobjects union

select top 1 2 as id,"李四" as xm,"女" as xb,"13" as bj from msysobjects union

select top 1 3 as id,"王五" as xm,"女" as xb,"14" as bj from msysobjects union

select top 1 4 as id,"趙六" as xm,"男" as xb,"15" as bj from msysobjects union

select top 1 5 as id,"孫七" as xm,"女" as xb,"16" as bj from msysobjects union

select top 1 6 as id,"吳八" as xm,"男" as xb,"17" as bj from msysobjects)  as temp;

2016-11-1  鶴望蘭

SQL一次性插入多條資料

新增一條記錄 insert intotablename col1,col2,col3 values val1,val2,val3 新增多條記錄 insert intotablename col1,col2,col3 selectval1,val2,val3 union all selectval1,...

oracle一次插入多條資料

insert into 表名 欄位1,欄位2 select 一 二 from dual union all select 三 四 from dual union all select 五 六 from dual union all select 七 八 from dual union all sel...

oracle一次插入多條資料

insert into 表名 欄位1,欄位2 select 一 二 from dual union all select 三 四 from dual union all select 五 六 from dual union all select 七 八 from dual union all sel...