Mysql sql语句备份

修改列名

ALTER TABLE josh_imei_bak.`province_city_county` CHANGE COLUMN c_name  col_name VARCHAR(50);

将一个表的数据更新到另一个表

UPDATE
  province_city_county
  INNER JOIN
    (SELECT
      base.col_name,
      derived.`id`
    FROM
      province_city_county AS derived
      JOIN province_city_county AS base
        ON derived.`pid` = base.`id`
    WHERE derived.type = 2
      AND derived.`col_name` = '市辖区') AS t_temp
    ON province_city_county.`id` = t_temp.id 
SET province_city_county.`col_name` = t_temp.`col_name`;

将表一存在但表二不存在的数据删除

DELETE t1 FROM t1 LEFT JOIN t2 ON t1.id=t2.id WHERE t2.id IS NULL ;

删除表数据

TRUNCATE TABLE t_county;

 

你可能感兴趣的:(MySql)