mysql> desc oldtable;
+---------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+--------------+------+-----+---------+----------------+
| uid | int(11) | NO | PRI | NULL | auto_increment |
| active | char(1) | NO | | NULL | |
+---------------+--------------+------+-----+---------+----------------+
mysql> desc newtable;
+------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+----------------+
| uid | int(11) | NO | PRI | NULL | auto_increment |
| active | tinyint(1) | NO | | 0 | |
+------------+--------------+------+-----+---------+----------------+
Run Code Online (Sandbox Code Playgroud)
我想将数据(转储)从oldtable移植到newtable.一个问题是,早期的表格使用char(1)表示存储值'Y'或'N'.现在newtable将它作为int存储为1或0.
如何在移植数据之前修复此问题?我应该使用shell脚本进行此类修复和移植吗?任何示例脚本或提示:)
INSERT INTO newtable
SELECT uid,IF(active='Y',1,0) as active FROM oldtable
Run Code Online (Sandbox Code Playgroud)
应该做的伎俩
| 归档时间: |
|
| 查看次数: |
189 次 |
| 最近记录: |