常用mysql語句總結(源自工作實踐)

來源:互聯網
上載者:User

1.修改列預設值
mysql> alter table mail_user_record alter work_exp_id set default 0;                                             

2.增加枚舉列
mysql> alter table mail_user_record add is_proof enum('0','1');

3.修改枚舉預設值
mysql> alter table mail_user_record modify is_proof enum('0','1')  not null default '0';

4.刪除列
mysql> alter table mail_user_record drop com_url;

5.查看建表sql
mysql> show create table career_talk;

6.複製表格
create table new like old;

7.刪除表id從1開始
truncate table name;

8.修改列名
alter table position_info_temp change position_name name varchar(100) null

9.修改列長度
alter table hr_auth modify column uuid char(37) ;

10.去除職位表中公司id、職位名、工作地點都一樣的重複記錄,只保留一條即可。
1)create table tmp as select min(id) as id from position_info_temp group by company_id,addr,name;
2)delete from position_info_temp where id not in (select id from tmp);
3)drop table tmp;
不能使用:
select * from position_info_temp where id not in(select min(id) from position_info_temp group group by company_id,addr,name);
報錯:#1093 - You can't specify target table 'blur_article' for update in FROM clause

不能先select出同一表中的某些值,再update這個表(在同一語句中)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.