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
通过AUTO_INCREMENT设置SQLINSERT语句的时候,要避免指定那个自增的字段.否则会发生主键的冲突。通过ALTERTABLE语句可以修改自增的数值,但是只能增加,不能减少。TRUNCATETABLE语句,会将自增ID重置为零。mysqlCREATETABLEtest_create_tab2(-idINTAUTO_INCREMENT,-valVARCHAR(10),-PRIMARYKEY(id)-)QueryOK,0rowsaffected(0.09sec)mysqlINSERTINTOtest_create_tab2(val)VALUES('NOid')QueryOK,1rowaffected(0.03sec)mysqlselectlast_insert_id()asid+----+|id|+----+|1|+----+1rowinset(0.00sec)mysqlINSERTINTOtest_create_tab2(val)VALUES('NOid2')QueryOK,1rowaffected(0.03sec)mysqlselectlast_insert_id()asid+----+|id|+----+|2|+----+1rowinset(0.00sec)mysqlselect*fromtest_create_tab2+----+---------+|id|val|+----+---------+|1|NOid||2|NOid2|+----+---------+2rowsinset(0.00sec)欢迎分享,转载请注明来源:内存溢出
评论列表(0条)