mysql 备忘录

一、清空数据库中一张表的命令:
    TRUNCATE TABLE '表名',这条命令比delete快很多,因为它实际上是删除了表,然后又重新新建了一张表。

二、查找字段重复的数据:
    select * from product where pid in (select pid from product group by pid having count(pid) > 1)

三、如何批量修改某个字符串字段:
    update product set ThumbUrl = concat("http://", ThumbUrl) where ThumbUrl like 'www%'; 这行语句是对以"www"开头的ThumbUrl字段的起始位置添加"http://"字符串

   update product set Url = replace(ThumbUrl,'http://192.168.1.1:8080','http://baidu.com'), ImageUrl = replace(ImageUrl,'http://192.168.1.1:8080','http://baidu.com') where Url like 'http://192.168.1.1:8080%'; 这行语句是将Url字段中包含"http://192.168.1.1:8080"的字段中"http://192.168.1.1:8080"全部替换成"http://baidu.com"

猜你喜欢

转载自chungang.iteye.com/blog/1664158