標籤:color 使用 ar 資料 2014 sp on c amp
第一章節:
共用鎖定(讀鎖),獨佔鎖定(寫鎖)
查詢資料表所使用的儲存引擎:
show table status like ‘表名‘ \G
轉換資料表的儲存引擎:
alter table 表名 engine=引擎名稱
as:
alter table mytable engine=Innodb;
---------
第三章節
char,varchar兄弟類型: binary, varbinary,用來儲存二進位字串,但是儲存的是位元組,而不是字元
blob和text分別以二進位和字元形式儲存大量資料
都有各自的資料類型家族:
text: tinytext, smalltext, text,mediumtext, longtext,(text相當於smalltext)
blob:tinyblob, smallblob, blob, mediumblob,longblob(blob相當於smallblob)
mysql不能索引這些 (blob,text...)的完整長度,也不能排序使用索引
enum類型,as:
create table enum_table(
e enum(‘yes‘, ‘no‘) not null,
....
);
日期和時間類型
datetime:精度為秒,格式如 YYMMDDHHMMSS,與時區不轉換,預設時格式如下:
2014-09-18 21:38:08
時間範圍為 1001-9999年
timestamp:保持了自 1970-1-1午夜(格林尼治標準時間)以來的秒數,與 unix的時間戳記相同,與mysql伺服器,作業系統,用戶端時區設定有關(推薦用)
有範圍的查詢,會失去索引的意義, 如
select * from where id>100 order by date asc
正則化(根據範式特徵,分表)與非正則化(非範式)
第四章
Mysql
select t1.id from test.t1 inner join test.t2 using(id) where t1.id > 500
==
where t1.id > 500 and t2.id > 500
相當於 using(id)其實就是 兩個表都使用了後來的 where 條件,但必須是兩個表的欄位名稱相同,局限於 mysql 資料庫
//統計顏色值
select sum(if(color=‘blue‘, 1, 0)) as blue,
sum(if(color=‘red‘), 1, 0) as red from 表名
==
select count(color=‘blue‘ or null) as blue,count(color=‘red‘ or null) as red from 表名
自訂變數,但是只能是數值的
tt(id, name);
as:
SET @id :=1; //表示從1開始
select name, @id := @id+1 as myid from tt limit 3;
則表示 id = 2開始接下來的三條資料
第五章
mysql 高效能