SQLServer数据迁移到Mysql表和字段comment丢失批量添加方法

第一步是用navicat将数据库迁移到MySQL。

第二步 批量添加表注解:在SQL Server 源库中执行一下sql语句,将所有表注解生成sql语句,将生成的sql语句在Mysql中执行,所有表注解批量修改成功

SELECT 'alter table ' + d.name + ' comment ''' 
+ convert(varchar(20),isnull(f.value,''),120)    +''';'
FROM  
  sysobjects d
right join  
sys.extended_properties f
on  
  d.id=f.major_id and f.minor_id=0
where d.name is not null 

将生成的sql语句在Mysql中执行,所有表注解批量修改成功 

第三步 批量添加字段注解: 在SQL Server 源库中执行一下sql语句,将所有表注解生成sql语句,将生成的sql语句在Mysql中执行,所有表注解批量修改成功

SELECT 
sql语句 = 'select CONCAT(''alter table ' + d.name 
+ ' modify column `' + a.name 
+ '` '',  column_type , '' comment ''''' 
+ convert(varchar(300), isnull(g.[value], ''''), 300) + ''''';'') aa  
from information_schema.columns 
where table_name=''' + d.name 
+ ''' and column_name=''' + a.name 
+ ''' and TABLE_SCHEMA = ''' + 'dreamplay' + ''' union  '
FROM syscolumns a
	LEFT JOIN systypes b ON a.xusertype = b.xusertype
	INNER JOIN sysobjects d
	ON a.id = d.id
		AND d.xtype = 'U'
		AND d.name <> 'dtproperties'
	LEFT JOIN syscomments e ON a.cdefault = e.id
	LEFT JOIN sys.extended_properties g
	ON a.id = G.major_id
		AND a.colid = g.minor_id
	LEFT JOIN sys.extended_properties f
	ON d.id = f.major_id
		AND f.minor_id = 0
WHERE g.value IS NOT NULL
ORDER BY a.id, a.colorder

 替换为自己的数据库名称

复制查询得到的SQL语句,在MySQL库中执行语句

 复制查询得到的SQL语句,在MySQL库中执行语句

 在参考文章上做了一些优化,以下为参考文章:

参考文章https://blog.csdn.net/mlj0381/article/details/95751644

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值