Mysql 在列中插入多个值

Mysql 在列中插入多个值,mysql,sql,sql-server,database,sql-server-2008,Mysql,Sql,Sql Server,Database,Sql Server 2008,我向现有表中添加了一个新列(列acadid、orgid、childid),现在我想为它插入值 alter table table1 add new_parent int insert into table (new_parent) select parent from (select parent from table2 o inner join table1 ou on ou.orgid=o.orgunitid) np 在这里: select parent from table2

我向现有表中添加了一个新列(列acadid、orgid、childid),现在我想为它插入值

alter table table1 add new_parent int

insert into table (new_parent) select parent from (select parent
from table2 o inner join table1 ou
on ou.orgid=o.orgunitid)  np
在这里:

 select parent
  from table2 o inner join table1 ou
  on ou.orgid=o.orgunitid
此查询为新父列提供多个值(多行)

但是上面的代码给了我以下错误:

无法将值NULL插入表的“acadid”列中 “tempdb.dbo.表1”“uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu000000”
如何修复它?

出现此错误消息的原因是您使用alter table语句向表1添加了一个新列,但没有更新现有行的此列值,您正在添加新行,其中只有该列填充了insert语句,并且在另一列上可能存在不允许空值的约束(主键约束?)

相反,您可能希望使用update更新现有行的新列的值,如:

update table1
set table1.new_parent = table2.parent
from table1 inner join table2 on table2.orgid=table1.orgunitid

似乎您的表中有一列“acadid”具有NOTNULL约束,并且您正在尝试插入一个新行,该新行的值仅为一列(新父列)。错误消息显而易见!将错误消息放在google中。首先在代码中更改
TABLE1
,然后尝试将记录插入名为
table
的表中,该表不是有效的SQL Server tablename,而不是插入
TABLE1
。这是哪个数据库管理系统?您已列出,我不想添加新行我想在现有行中添加new_parent的值。@user3325454:尝试使用
updatetable1 set new\u parent=(选择…)where orgid=…
或使用
where orgid in(…)
进行相同操作。