设置某列默认值:alter table a alter column c set default "xxx";
修改某列属性:ALTER TABLE a MODIFY COLUMN c VARCHAR(20);
设置某一列不为空:alter table a modify c varchar(20) not null;
修改列明:alter table a change c newname varchar(20);
修改某个字段值:update tablename set a='xx' where c='xxx';
插入记录:insert into tablename(a,b,c) values(xxx,xxx,xxx);
针对某个字段a的去重复搜索,且搜到的结果是最新记录:
select * from tablename T where not exists(select* from tablename where a=T.a and updatetime>T.updatetime);
搜索结果按照列a的值升序排列:select * from tablename order by a asc;
搜索结果按照列a的值降序排列:select * from tablename order by a desc;
给有重复记录的表添加联合唯一索引,添加后自动去重复:alter ignore table a add unique index(c1,c2);
mysql给表去重复(许多去重复的语句都需要一边查询表A,一边修改表A,而mysql不允许这样,所以去重复就要先通过建立临时表的方式,如下4步):
create table tmp_users
技术相关更多文章猛击:哇啦天堂论坛技术区