简体   繁体   English

在表中插入多行

[英]Inserting Multiple Rows into a Table

I've written the code below and keep getting an error for incorrect syntax 我已经在下面编写了代码,并由于语法​​错误而不断收到错误消息

It said at line 10 near the , - so this line: 它说,在10号线附近, -所以这行:

values(1, 'Stolz', 'Ted', 25000, NULL), )

If I only try to insert the first row of data it works fine, it's when I try to do multiple. 如果我仅尝试插入第一行数据,则可以正常工作,这是我尝试执行多次操作的时候。 Am I missing something really simple? 我是否错过了一些非常简单的事情?

Drop Table #TPerson

CREATE TABLE #TPerson 
(
    personid int PRIMARY KEY NOT NULL,
    lastname varchar(50) NULL,
    firstname varchar(50) NULL,
    salary money NULL,
    managerid int NULL
);

Insert Into #TPerson(Personid, lastname, firstname, salary, managerid)
values (1, 'Stolz', 'Ted', 25000, NULL),
       (2, 'Boswell', 'Nancy', 23000, 1),
       (3, 'Hargett', 'Vincent', 22000, 1),
       (4, 'Weekley', 'Kevin', 22000, 3),
       (5, 'Metts', 'Geraldine', 22000, 2),
       (6, 'McBride', 'Jeffrey', 21000, 2),
       (7, 'Xiong', 'Jay', 20000, 3)

You can write something like this: 您可以这样写:

Insert Into #TPerson(Personid,lastname,firstname,salary,managerid)
select 1,'Stolz','Ted',25000,NULL
union all select 2,'Boswell','Nancy',23000,1
union all select 3,'Hargett','Vincent',22000,1
union all select 4,'Weekley','Kevin',22000,3
union all select 5,'Metts','Geraldine',22000,2
union all select 6,'McBride','Jeffrey',21000,2
union all select 7,'Xiong','Jay',20000,3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM