瀛楃锛�
char(10)->瀹氶暱銆�10涓瓧绗﹀搴︺�傚鏋滃彸渚т笉澶燂紝鍒欑┖鏍艰ˉ榻愶紝鍙栧嚭鏉ョ殑鏃跺�欏垹闄ょ┖鏍笺��
varchar(10)->鍙橀暱銆佹渶澶�10涓瓧绗�
濡傦細瀛樺鍚嶇殑鏃跺�欙紝娌″繀瑕佷负浜嗛偅鍑犱釜闀垮害鍘讳娇鐢╲archar锛屼娇鐢ㄥ畾闀垮幓瀛樺偍浼氭彁楂樻晥鐜囷紒
鏃ユ湡鏃堕棿锛�
Year->1瀛楄妭->95||1995->銆�1901-2155銆�
Date->鏃ユ湡->1998-12-31->銆�1000-01-01->9999-12-31銆�
Time->鏃堕棿->13:56:23->->銆�-838:59:59->838:59:59銆�
datetime->鏃堕棿鎴�->1970-01-01 00:00:00鍒板綋鍓嶇殑绉掓暟
Tip锛欴ate聽 Date聽 datetime鍦╥nsert鐨勬椂鍊欓渶瑕佸姞涓婂紩鍙� 銆佸疄闄呭紑鍙戜腑锛屼竴鑸笉鏄敤杩欎簺锛岀洿鎺ヤ娇鐢�787657676绫讳技浜庤繖涓牱瀛愮殑鏁村舰鏉ュ瓨鍌紙鍏跺疄灏辨槸浠�1970骞�0鐐逛负鍑嗭紝鐒跺悗鎹㈢畻鎴愮鏁板瓨鍌級銆傛悶iOS寮�鍙戠殑鑲畾閬囧埌杩�
not null:
1銆丯ULL鏌ヨ涓嶄究銆佺储寮曟晥鐜囦笉楂樸�佹墍浠ュ疄鐢ㄤ腑閬垮厤鍒楃殑鍊间负NULL
2銆佸0鏄庡垪鐨勫�间负NOT NULL锛屽苟涓攄efault涓�涓粯璁ゅ��
涓婚敭涓庤嚜澧烇細
涓婚敭primary key姝ゅ垪涓嶉噸澶嶏紝灏辫兘澶熷尯鍒嗘瘡涓�琛岋紒
涓�涓〃涓彧鑳芥湁涓�涓猘uto_increment,鑰屼笖杩欎竴鍒楀繀椤诲姞涓妏rimary key绱㈠紩
淇敼鍒楋細
alter table tableName add 鍒楀悕 绫诲瀷 灞炴��... ->榛樿鍦╰able鐨勬渶鍚�
alter table tableName add 鍒楀悕 绫诲瀷 灞炴�� after 鍒跺畾鍒楀悕->灏嗗鍔犲埌鍒跺畾鐨勫垪鍚嶅悗闈�
alter table tableName drop column 鍒楀悕
alter table tableName change 鍒楀悕 鏂板悕瀛� 绫诲瀷 灞炴��...
alter table tableName modify 鍒楀悕 鏂板睘鎬�...
change鍙互淇敼鍒楀悕锛屼絾鏄痬odify涓嶈兘淇敼鍒楁槑锛屽彧鑳戒慨鏀瑰垪鐨勫睘鎬�
瑙嗗浘(View):
create view vgoods as select goods_name , goods_id from goods;
view鍙堣绉颁负铏氭嫙琛紝view鏄痵ql璇彞鐨勪竴涓煡璇㈢粨鏋溿��
濂藉锛�
1銆佹潈闄愭帶鍒舵椂鍙互鐢紱濡傦細鏌愬嚑涓垪鍏佽鐢ㄦ埛鏌ヨ锛屽叾浠栧垪涓嶅彲浠ャ��
create view tmpview as select goods_name from goods;
select * from tmpview;
2銆佺畝鍖栧鏉傜殑鏌ヨ锛�
3銆佷慨鏀圭墿鐞嗚〃锛岃櫄鎷熻〃涓�瀹氫細琚慨鏀癸紱濡傛灉鐗╃悊琛ㄥ畬鍏� 涓� 涓�瀵瑰簲鐫�铏氭嫙琛紝鍒欎慨鏀硅櫄鎷熻〃浼氭槧灏勫埌鐗╃悊琛ㄣ�備絾鏄紝姣斿铏氭嫙琛ㄦ槸姹傚钩鍧囦箣绫荤殑锛屼笉鏄竴涓�瀵瑰簲鐨勶紝鍒欎笉鑳戒慨鏀硅櫄鎷熻〃锛屽洜涓烘病娉曠‘璁ゅ埌鐗╃悊琛ㄧ殑鍏蜂綋鐨勬煇涓�涓綅缃��
鏌ヨview鏈変袱绉嶅彲鑳斤細
1銆佸皢鍒涘缓view鐨勮鍙ュ拰鏌ヨview鐨勮鍙ュ悎骞讹紝鐒跺悗鐩存帴鏌ョ墿鐞嗚〃銆傝繖绉嶆柟寮忓彨鍋歮erge
2銆佸鏋渧iew鐨勫舰鎴愬氨姣旇緝澶嶆潅浜嗭紝閭i鍏堟煡璇㈢墿鐞嗚〃锛屽湪鍐呭瓨涓舰鎴愪竴涓獀iew锛岀劧鍚庡啀鏌ヨ杩欎釜view銆�
浣跨敤merge鏂瑰紡锛歝reate algorithm-merge view view1 as select ... from goods;
浣跨敤temptable:create algorithm-temptable view view2 as select ... from goods;
鑷繁鎼炰笉瀹氬氨璁╂暟鎹簱鑷姩鍐冲畾锛�
琛╘瑙嗗浘绠$悊璇彞锛�
鏌ョ湅鎵�鏈夎〃锛歴how tables锛�
鏌ョ湅缁撴瀯锛歞esc table/view-name锛�
鏌ョ湅寤鸿〃/瑙嗗浘杩囩▼锛歴how create 聽table/view 聽table/view-name锛�
鍒犻櫎琛�/瑙嗗浘锛歞rop table table/view-name锛�
鏌ョ湅琛ㄧ殑璇︾粏淇℃伅锛歴how table status锛涘姞涓奬G浼氱珫鐫�鏄剧ず
鏀硅〃鍚嶏細rename table old-name to new-name;
娓呯┖琛ㄦ暟鎹細truncate锛�
delete鍜宼runcate鐨勫尯鍒細
delete 聽from table-name where id = 2锛�(id鏄痑uto_increment鐨�)锛屼笅娆″啀鎻掑叆涓�涓暟鎹殑鏃跺�欙紝id浼氱洿鎺ヤ粠3寮�濮嬶紝鑰屼笉浼氫粠2寮�濮嬶紝鍗充娇id=2鐨勫凡缁忚鍒犳帀銆�
truncate table-name;鐩稿綋浜庢墽琛屼簡涓ゆ锛岄鍏坉rop鎺夎繖涓猼able銆傜劧鍚庡張閲嶆柊寤虹珛涓�娆★紒
鎵�浠�...鑷繁浣撲細
瀛樺偍寮曟搸锛�
Myisam:鍗曠函鐨勫瓨鍙栬�屽凡锛屾病鏈変粈涔堟鏌ヤ箣绫荤殑锛�
InnoDB:瀛樺彇閮芥湁妫�鏌ワ紝鏈夎嚜宸辩殑鏃ュ織锛�
浠ヤ笂涓よ�呭弬鑰冪嚂鍗佸叓鐨勬瘮鍠�!
eg锛歝reate....( ... ) engine-InnoDB default charset-utf8;
瀛楃闆嗕贡鐮侀棶棰橈細
鏂囨湰鏈潵鐨勫瓧绗﹂泦涓庡睍绀虹殑瀛楃闆嗕笉涓�鑷村氨瀵艰嚧浜嗕贡鐮侊紒
鎴戣瀛樼殑绫诲瀷鏄痝bk/utf8锛歴et character_set_client = gbk/utf8;
鎴戣鍙栨暟鎹紝璇疯繑鍥炵粰鎴慻bk/utf8绫诲瀷鐨勬暟鎹細set character_set_result = gbk/utf8;
杩炴帴鍣ㄤ笉瑕佽缃瘮杈冨皬鐨勫瓧绗﹂泦锛屼笉鐒朵細鎹熷け鎺夋暟鎹紝鑰屼笖鏄笉鍙�嗙殑锛�
濡傛灉client銆乺esult銆乧onnect閮借缃负鍚屼竴鏍峰瓧绗﹂泦锛屾瘮濡倁tf8锛岄偅灏卞彲浠ョ洿鎺ョ畝鍐欎负set names utf8锛�
涔辩爜鐨勮瘽妫�鏌ュ洓涓湴鏂癸細php鏂囦欢绫诲瀷銆乸hp mate绫诲瀷(meta charset='utf-8')銆佸垱寤虹殑table鐨勭被鍨嬨�佹湁娌℃湁鎵цset names utf8锛�
鏍″闆嗗氨鏄竴绉嶆帓搴忚鍒欍��
绱㈠紩锛�
浣滅敤锛�
1銆佺储寮曞氨鐩稿綋浜庢暟鎹殑鐩綍锛岃兘蹇�熷畾浣嶆暟鎹殑浣嶇疆銆�
2銆佺储寮曟槸鏈変唬浠风殑锛屽畠鎻愰珮浜嗘煡璇㈢殑閫熷害锛屼絾鏄崯鑰椾簡澧炲垹鏀圭殑鏁堢巼銆�
3銆佷竴鑸湪鏌ヨ姣旇緝棰戠箒鐨勫垪涓婂姞绱㈠紩锛岃�屼笖閲嶅鐜囦綆鐨勭殑鍒椾笂鏁堟灉鏇村ソ銆傛瘮濡傦細鎬у埆锛屽彧鏈夌敺銆佸コ(shit锛屽叾浠栫殑涓嶈�冭檻)锛屾墍鏈夊氨娌″繀瑕佸姞涓婄储寮曘��
绫诲瀷锛�
鏅�氱储寮昸ey銆佸敮涓�绱㈠紩unique key銆佷富閿储寮昿rimary key銆佸叏鏂囩储寮�(鍦ㄤ腑鏂囩幆澧冧笅鏃犳晥,涓�鑸敤绗笁鏂圭殑瑙e喅鏂规)
绱㈠紩鍦ㄦ墍鏈夌殑鍒楄缃畬浜嗕箣鍚庤缃紒
鍐椾綑绱㈠紩:
灏辨槸鍦ㄦ煇涓垪涓婂瓨鍦ㄥ涓储寮曘��
绱㈠紩鎿嶄綔锛�
show index from table-name \G;
alter table table-name drop index index-name;/drop index index-name on table-name; 聽(鍒犻櫎绱㈠紩)
alter table table-name add index unique index-name(line-name);(澧炲姞绱㈠紩)
alter table table-name add primary key (line-name);(澧炲姞涓婚敭绱㈠紩锛屼笉闇�瑕佺储寮曞悕)
alter table table-name drop primary key;(鍒犻櫎涓婚敭绱㈠紩)
浜嬪姟锛氾紙myisam涓嶆敮鎸佷簨鍔★級
鐗规�э細闅旂鎬с�佸師瀛愭�с�佷竴鑷存�с�佹寔涔呮�э紙涓�鏃ommit涔嬪悗锛屽氨娌℃硶rollback锛夈��
start transaction;鍚敤浜嬪姟
commit;纭
rollback;鍥炴粴
鎴戠畻鏄煡閬撲粈涔堟槸浜嬪姟浠�涔堜簨鍥炴粴浜嗭紒锛�