如何在Microsoft Access表中插入多行?

时间:2014-10-23 05:12:17

标签: sql ms-access sql-insert multiple-records

我已尝试过各种方法,我可以通过Google在Access中插入多行查询 这些都不适合我:

INSERT INTO MyTable (fld02, fld02, fld03)
SELECT '1','2','3'
UNION SELECT '4','5','6'
UNION SELECT '7','8','9'

INSERT INTO faculty1 (first_name, last_name, gender, birthdate, address, city, phone, salary, area_of_expertise)
VALUES ('a','b','Male','January 15, 1955','4202 E Fowler Ave','Tampa','813-974-2268','50000','Computer Engineering');
VALUES ('c','d','Male','October 22, 1948','4202 E Fowler Ave','Tampa','813-974-1538','80000','Computer Engineering');
VALUES ('e','f','Male','May 15, 1933','4202 E Fowler Ave','Tampa','813-974-4425','120000','Computer Engineering');
VALUES ('g','h','Female','December 3, 1960','4202 E Fowler Ave','Tampa','813-974-1276','60000','Computer Engineering');
VALUES ('i','j','Female','November 17, 1962','4202 E Fowler Ave','Tampa','813-974-2154','62000','Computer Engineering');


INSERT INTO faculty1 (first_name, last_name, gender, birthdate, address, city, phone, salary, area_of_expertise)
VALUES ('a','b','Male','January 15, 1955','4202 E Fowler Ave','Tampa','813-974-2268','50000','Computer Engineering');

INSERT INTO faculty1 (first_name, last_name, gender, birthdate, address, city, phone, salary, area_of_expertise)
VALUES ('c','d','Male','October 22, 1948','4202 E Fowler Ave','Tampa','813-974-1538','80000','Computer Engineering');

INSERT INTO faculty1 (first_name, last_name, gender, birthdate, address, city, phone, salary, area_of_expertise)
VALUES ('e','f','Male','May 15, 1933','4202 E Fowler Ave','Tampa','813-974-4425','120000','Computer Engineering');

INSERT INTO faculty1 (first_name, last_name, gender, birthdate, address, city, phone, salary, area_of_expertise)
VALUES ('g','h','Female','December 3, 1960','4202 E Fowler Ave','Tampa','813-974-1276','60000','Computer Engineering');

INSERT INTO faculty1 (first_name, last_name, gender, birthdate, address, city, phone, salary, area_of_expertise)
VALUES ('i','j','Female','November 17, 1962','4202 E Fowler Ave','Tampa','813-974-2154','62000','Computer Engineering');

我甚至尝过一次参赛作品,但也没办法。

INSERT INTO faculty1 ( first_name, last_name, gender, birthdate, address, city, phone, salary, area_of_expertise )
VALUES ('a', 'b', 'Male', 'January 15, 1955', '4202 E Fowler Ave', 'Tampa', '813-974-2268', '50000', 'Computer Engineering');

我的CREATE声明有问题吗?

CREATE TABLE faculty1
(
    facultynumber int PRIMARY KEY,
    first_name CHAR(20),
    last_name CHAR(20),
    gender CHAR(10),
    birthdate CHAR(25),
    address CHAR(50),
    city CHAR(20),
    phone CHAR(20),
    salary INTEGER,
    area_of_expertise CHAR(20)
);

http://www.pixhost.org/show/1360/23620036_access_error.jpg


这令人惊讶地奏效。 Access无法处理您没有给出主键吗?我认为这是可选的。

http://www.w3schools.com/sql/sql_insert.asp

INSERT INTO faculty1 ( facultynumber, first_name, last_name, gender, birthdate, address, city, phone, salary, area_of_expertise )
VALUES ('5', 'a', 'b', 'Male', 'January 15, 1955', '4202 E Fowler Ave', 'Tampa', '813-974-2268', '50000', 'Computer Engineering');

2 个答案:

答案 0 :(得分:0)

薪水定义为整数,但您尝试使用引号插入。此外,您必须提供教师编号或使其成为身份/计数器

INSERT INTO faculty1 (facultynumber, first_name, last_name, gender, birthdate, address, city, phone, salary, area_of_expertise )
VALUES (1, 'a', 'b', 'Male', 'January 15, 1955', '4202 E Fowler Ave', 'Tampa', '813-974-2268', 50000, 'Computer Engineering');

答案 1 :(得分:0)

如果要自动生成主键,则需要将列定义为自动编号类型。

CREATE TABLE  faculty1
(
  facultynumber PRIMARY KEY AUTOINCREMENT,
  ...

此主题中的更多细节:https://stackoverflow.com/a/1072938/2712185