MySQL中的binlog和redo淺析(r12筆記第5天)
三大資料型別: |
字串 |
varchar |
|
數值 |
int |
||
日期 |
data、time |
||
增、刪、改、查: |
增: |
insert into |
|
刪: |
delete from <表名> |
||
改: |
update <表名> set 欄位 |
||
查:基本查詢:select * from <表名> |
|||
查詢字句:where: select * from <表名> where 條件 |
|||
|
排序:select * from <表名> order by <按照某個欄位排序> |
||
分組:select * from <表名> group by <按照某個欄位分組> |
|||
去重:select distinct<欄位名> from <表名> |
|||
表關聯查詢:兩表關聯:內連線 inner join:select t1(*),t2(*) from t1 inner join t2 on t1.id=t2.id; 左連線 left join : select t1(*),t2(*) from t1 left join t2 on t1.id=t2.id; 右連線 right join: select t1(*),t2(*) from t1 right join t2 on t1.id=t2.id; 全連線 左連線union 右連線: select t1(*),t2(*) from t1 left join t2 on t1.id=t2.id Union select t1(*),t2(*) from t1 right join t2 on t1.id=t2.id;
三表關聯:表一關聯表二,再關聯表三: select e(*),t3(*)from(select t1(*),t2(*),t3(*) from t1 left join t2 on t1.id=t2.id ) e Left join select e(*),t2(*) from e left join t3 on e.id=t3.id;
子查詢:單個值:select name from t1 where age in (1); 多個值作為範圍:select name from t1 where age in (1,10); 多個值作為中間結果:select name from t1 where age in (select age from t2 where age >10);
檢視:建立檢視:create view v_a(編號,姓名)as select * from a with check option; 建立多表檢視:create view v_abc(編號,姓名,年齡)as select a.id,a.name,b.age from a,b where a.id = c.id with check option;
索引:普通索引:直接建立索引:create index index_name on table (column) 修改表結構新增索引:alert table table_name index index_name(column); 唯一索引:create unique index index_name on(column); 複合索引:create index index_name on table (name,age,id)
事務:開啟:begin 提交:commit 回滾:rollback
觸發器:create trigger t_name Insert/delete/update/alert on <表名> For each row Begin Sql語句 End;
儲存過程:create procedure test() Begin Select * from user; End;
查詢優化:
|
|||
|