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
insert语句不起作用。 ','。
附近的语法不正确答案 0 :(得分:3)
在SQL Server 2005中,您无法在,
:
values
替换:
INSERT INTO Employees
VALUES(N'593705', N'Frank Somah', N'20061004', 26.15),
(N'720947', N'Paul Handsome', N'20000802', 36.05);
SELECT
UNION ALL
或多个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
答案 1 :(得分: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);
答案 2 :(得分: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