在ACCESS的查询中,通常一次只能插入一条记录,如果同时有多条记录要追加,就要写多个查询,这有点麻烦。能不能在一个查询中实现多条记录的追加呢?经多方查找与测试,发现可以用以下方法实现,现分享给大家。
Insertt 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 是系统表,只要创建对象,此表中就一定有记录,此表也可以用其它表代替,不过要保证表中至少有一条记录,至于记录的内容在此无关紧要。
另一写法:
Insertt 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;