-1
CREATE DATABASE Exercise

USE Exercise;
Go

CREATE TABLE Employees
(
EmployeeNumber nchar(10),
EmployeeName nvarchar(50),
DateHired datetime,
HourlySalary money
);
GO


INSERT INTO Employees
VALUES(N'593705', N'Frank Somah', N'20061004', 26.15),
(N'720947', N'Paul Handsome', N'20000802', 36.05);
GO

INSERT INTO Employees(EmployeeName, EmployeeNumber, DateHired)
VALUES(N'Clarice Simms', N'971403', N'20011112');
GO

插入语句不起作用。',' 附近的语法不正确。

4

3 回答 3

3

在 SQL Server 2005 中,您不能使用,between values

代替:

INSERT INTO Employees
VALUES(N'593705', N'Frank Somah', N'20061004', 26.15),
(N'720947', N'Paul Handsome', N'20000802', 36.05);

使用SELECTwithUNION ALL或 multiple INSERT...VALUES...

INSERT INTO Employees
SELECT N'593705', N'Frank Somah', N'20061004', 26.15 
UNION ALL
SELECT N'720947', N'Paul Handsome', N'20000802', 36.05

INSERT INTO Employees
Values(N'593705', N'Frank Somah', N'20061004', 26.15)

INSERT INTO Employees
Values(N'720947', N'Paul Handsome', N'20000802', 36.05)
GO

INSERT INTO Employees(EmployeeName, EmployeeNumber, DateHired)
VALUES(N'Clarice Simms', N'971403', N'20011112');
GO

因此,您的完整脚本将是:

CREATE TABLE Employees
(
    EmployeeNumber nchar(10),
    EmployeeName nvarchar(50),
    DateHired datetime,
    HourlySalary money
);
GO


INSERT INTO Employees
select N'593705', N'Frank Somah', N'20061004', 26.15
union all
select N'720947', N'Paul Handsome', N'20000802', 36.05
GO

INSERT INTO Employees(EmployeeName, EmployeeNumber, DateHired)
VALUES(N'Clarice Simms', N'971403', N'20011112');
GO
于 2012-08-21T14:12:18.430 回答
1

您可以使用多个插入语句。代替

INSERT INTO Employees
VALUES(N'593705', N'Frank Somah', N'20061004', 26.15),
(N'720947', N'Paul Handsome', N'20000802', 36.05);

你可以做

INSERT INTO Employees
    VALUES (N'593705', N'Frank Somah', N'20061004', 26.15);
INSERT INTO Employees
    VALUES (N'720947', N'Paul Handsome', N'20000802', 36.05);
于 2012-08-21T14:13:35.687 回答
0

我猜你是在 SQL Server 2005 上工作的。它在 2005 上不支持多值插入。你需要一个一个地插入它。

INSERT INTO Employees
VALUES(N'593705', N'Frank Somah', N'20061004', 26.15)
GO
INSERT INTO Employees
VALUES(N'720947', N'Paul Handsome', N'20000802', 36.05)
GO
INSERT INTO Employees(EmployeeName, EmployeeNumber, DateHired)
VALUES(N'Clarice Simms', N'971403', N'20011112')
GO
于 2012-08-21T14:14:22.677 回答