Mysql 在一个表中为另一个表中的所有行插入值
我想编写一个sql脚本,它将其他表中所有ID的一些值插入表中Mysql 在一个表中为另一个表中的所有行插入值,mysql,sql,Mysql,Sql,我想编写一个sql脚本,它将其他表中所有ID的一些值插入表中 create table person ( id int(11) not null auto_increment, name varchar(255), primary key (id) ); insert into person values (null, 'John'), (null, 'Sam'); select * from person; id | name ---------- 1 | Jo
create table person
(
id int(11) not null auto_increment,
name varchar(255),
primary key (id)
);
insert into person
values (null, 'John'), (null, 'Sam');
select * from person;
id | name
----------
1 | John
2 | Sam
create table phone_details
(
id int(11) not null auto_increment,
person_id int(11),
phone int(11),
constraint person_ibfk_1 foreign key (person_id) references person (id) on delete no action,
primary key (id)
);
现在,在phone_details表中,我需要以下内容:
id | person_id | phone
----------------------------
1 | 1 | 9999999999
2 | 2 | 9999999999
我该怎么做?目前,我正在使用Java编写这个一次性脚本,但我认为在sql中一定有一种方法可以做到这一点。您可以使用
插入到。。。选择
语法:
INSERT INTO phone_details(person_id,phone)
SELECT id, 99999999
FROM person;
将其视为VARCHAR
您可以使用
插入到。。。选择
语法:
INSERT INTO phone_details(person_id,phone)
SELECT id, 99999999
FROM person;
将其视为VARCHAR
您可以使用
插入到。。。选择
语法:
INSERT INTO phone_details(person_id,phone)
SELECT id, 99999999
FROM person;
将其视为VARCHAR
您可以使用
插入到。。。选择
语法:
INSERT INTO phone_details(person_id,phone)
SELECT id, 99999999
FROM person;
将其视为VARCHAR
我在上面的查询中出错:SQL错误[1054][42S22]:“字段列表”中的未知列“person\u id”我在上面的查询中出错:SQL错误[1054][42S22]:“字段列表”中的未知列“person\u id”我在上面的查询中出错:SQL错误[1054][42S22]:字段列表中的未知列“person\u id”我在上面的查询中遇到错误:SQL错误[1054][42S22]:字段列表中的未知列“person\u id”