設置某列默認值: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_usersselect min(`id`),
`name` from
users group byname;
truncate table users;
insert into users select * from tmp_users;
drop table tmp_users ;
技術相關更多文章猛擊:哇啦天堂論壇技術區