我运行此声明:
CREATE TABLE Persons
(
PersonID int,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255)
);
INSERT INTO Persons (PersonID, LastName, FirstName, Address, City)
VALUES ((001, 002), ("f", "Doe"), ("f", "John"), ("6256 german Ave S", "1234 random ave"), ("berlin", "Rondomville"))
并收到此错误:
Operand should contain 1 column(s)
我不知道我到底做错了什么。
如果我运行下面的声明,那么everthing工作正常:
CREATE TABLE Persons
(
PersonID int,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255)
);
INSERT INTO Persons (PersonID, LastName, FirstName, Address, City)
VALUES(001, "f", "a", "6254 german Ave S", "berlin")
答案 0 :(得分:6)
正确的语法是:
INSERT INTO Persons
(PersonID, LastName, FirstName, Address, City)
VALUES (1, 'f', 'f', '6256 german Ave S', 'berlin'),
(2, 'Doe', 'John', '1234 random ave', 'Rondomville')
或者,您可以使用INSERT INTO ... SELECT
UNION ALL
INSERT INTO Persons
(PersonID, LastName, FirstName, Address, City)
SELECT 1, 'f', 'f', '6256 german Ave S', 'berlin'
UNION ALL SELECT 2, 'Doe', 'John', '1234 random ave', 'Rondomville'
答案 1 :(得分:1)
INSERT INTO Persons (PersonID, LastName, FirstName, Address, City)
Select 001, "f", "a", "6254 german Ave S", "berlin"
UNION ALL
Select 002, "f", "a", "333 deutch strasse", "freiburg"