分享

MySQL 已有数据的表 调整字段顺序

 小样样样样样样 2022-11-11 发布于北京

目的

解决

生成一张字段顺序正确的表,把以前那张表的数据复制过去

生成一张正确结构的表,pms_goods_sku_stock2


查询表的所有字段

	select 
		COLUMN_NAME
	from information_schema.COLUMNS 
	where table_name = 'pms_goods_sku_stock2' 
		and table_schema = 'blade2'; 

复制的sql语句

insert into 表1 (列名1,列名2,列名3) select 列1,列2,列3 from 表2

生成的sql

insert into pms_goods_sku_stock2 
(
	id,product_id,goods_id,store_id,product_name,goods_name,name,store_name,primary_store_name,sp_data,sku_code,price,sale_price,all_sale_price,all_sale_price_update_time,profit,sale,stock,low_stock,pic,related_sale,related_product_id,related_product_name,real_num,sort,remark,create_user,create_time,update_user,update_time,status,is_deleted,tenant_id
) 
select 
	id,product_id,goods_id,store_id,product_name,goods_name,name,store_name,primary_store_name,sp_data,sku_code,price,sale_price,all_sale_price,all_sale_price_update_time,profit,sale,stock,low_stock,pic,related_sale,related_product_id,related_product_name,real_num,sort,remark,create_user,create_time,update_user,update_time,status,is_deleted,tenant_id
from pms_goods_sku_stock

remark

中间截图的时候 缺了一个字段

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多