简体   繁体   English

插入多行有条件

[英]insert multiple rows with condition

I need to insert multiple rows for current column in a table.我需要为表中的当前列insert多行。

sql sql

insert into pa
(cd)
values
((select 'SU' from pa where pa_id = 101))
 ;

What is the correct syntax?什么是正确的语法? Getting error, cannot insert null value.获取错误,无法插入空值。

insert into pa (cd)
select 'SU' 
from pa
where pa_id = 101

I suspect that you want an update instead:我怀疑你想要update

update pa
    set cd = 'SU'
    where pa_id = 101;

insert inserts a new row. insert插入一个新行。 All the columns not included in the insert are set to NULL -- which is no doubt causing your error. insert中未包含的所有列都设置为NULL - 这无疑会导致您的错误。

You seem to want to change the value in an existing row;您似乎想更改现有行中的值; update does that. update这样做的。

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

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