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

目的

解决

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

生成一张正确结构的表,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

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

原文地址:https://www.cnblogs.com/guxingy/p/14500435.html