insert into table1 values(數(shù)據(jù)) insert into table2 values(數(shù)據(jù)) insert into table3 values(數(shù)據(jù)) 一起提交就是多個表同時添加
成都創(chuàng)新互聯(lián)專注于綦江網(wǎng)站建設服務及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗。 熱誠為您提供綦江營銷型網(wǎng)站建設,綦江網(wǎng)站制作、綦江網(wǎng)頁設計、綦江網(wǎng)站官網(wǎng)定制、小程序定制開發(fā)服務,打造綦江網(wǎng)絡公司原創(chuàng)品牌,更為您提供綦江網(wǎng)站排名全網(wǎng)營銷落地服務。
mysql無論如何也做不到用一條語句給兩張表插入數(shù)據(jù)。
理由:一個insert語句僅能在一個表中插入,這是語法的規(guī)定。
工具:mysql 5.6
步驟(即插入數(shù)據(jù)舉例):
1、如user表有如下數(shù)據(jù):
2、要將一條新數(shù)據(jù),id為6,name為lilei插入表中,用如下語句:
insert?into?user(id,name)?values?(5,'lilei');
3、插入后結(jié)果:
給你幾個情況
1.如果是累加name是這樣的
update b
set name=name+a.name
from a
where a.url=b.http
2.直接插入
insert b(name)
select name
from a join b on a.url=b.http
3.替換原來的name
update b
set name=a.name
from a
where a.url=b.http
1、先添加完,刪除所有重復的記錄,再insert一次
insert into A select * from B;
insert into A select * from C;
insert into A select * from D;
2、刪除重復的記錄只保留一行
delete from A where name in (select id from t1 group by id having count(id) 1)and rowid not in (select min(rowid) from t1 group by id having
count(*)1);
3、記錄一下這些重復的記錄,
mysql -uroot -p123456 -Ddb01 -e 'select b.id from t1 b group by id having count(b.id) 1' | tail -n +2 repeat.txt
刪除全部重復的記錄
delete from A where name in (select name from t1 group by name having count(name) 1;);
再次插入多刪的重復記錄
#!/bin/sh
for id1 in `cat repeat.txt`;do
mysql -uroot -p123456 -Ddb01 -e "insert into A select * from B where id='${id1}'"
done