在网上只能查到
Mysql 不能使用select into
其实是不对的= =
mysql的select xx into 变量 才对= =
用法不同而已= =b
如果在MySQL中直接使用如下select into的SQL,会有报错:
select * into t2 from t1;
如何解决呢
(一)、使用 create table 来创建一个结构除了 id 不要 mytest表
create table mytest (select aid, title, subtitle, duty, attachment, doccode, docpage, doctime, quanzonghao, categorynumber, partnumer,
secretlevel, cansee, canadd, canupdate, candel, createtime, remark, arttype from izqhr_archives);
(二)使用 insert into select 进行插入就可以了。
INSERT INTO SELECT语句复制表数据部分列和常值
Insert
into
Table2(a, c, d)
select
a,c,5
from
Table1
或:
Insert
into
Table2
select
*
from
Table1
insert INTO izqhr_archives(aid, title, subtitle, duty, attachment, doccode, docpage, doctime, quanzonghao, categorynumber, partnumer,
secretlevel, cansee, canadd, canupdate, candel, createtime, remark, arttype) select aid, title, subtitle, duty, attachment, doccode, docpage, doctime, quanzonghao, categorynumber, partnumer,
secretlevel, cansee, canadd, canupdate, candel, createtime, remark, arttype from mytest;
(三)、
显示更新后的结果
select
*
from
Table2
删除测试表
drop
TABLE
Table2