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

2021-06-07 18:02:01 字數 1270 閱讀 8057

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這個表(在同一語句中)

常用mysql語句 常用MySql語句

新建資料表 drop table if exists ga game way create table ga game way id int 11 unsigned not null auto increment comment id primary key id using btree,主鍵 un...

工作一年總結 sql語句 mysql

1 知道了if的用法 2 知道了if null的用法 3 表結構 查詢身份同時為 演員,導演和編劇的使用者。結果 4 表結構 查詢role為 導演和演員 的使用者 結果 select table name from information schema.columns where table sch...

常用MySQL語句

1.庫的操作 2.表的操作 3.索引的操作 4.檢視的操作 5.資料的操作 建立資料庫 create database database name 檢視資料庫 show databases 選擇資料庫 use database name 刪除資料庫 drop database database na...