1.鍒涘缓鏁版嵁搴撳紑濮�
CREATE DATABASE 鏁版嵁搴撳悕绉般��锛堣繖鏍蜂細浣跨敤mysql榛樿鐨勫瓧绗﹂泦锛�
锛掞紟鍒涘缓鎸囧畾瀛楃闆嗙殑鏁版嵁搴�
CREATE DATABASE 鏁版嵁搴撳悕绉般��CHARSET=utf8/gbk/gb2312
3.淇敼鏁版嵁搴�
ALTER DATABASE 鏁版嵁搴撳悕绉般��CHARSET=瀛楃闆�
琛ㄧ殑鍒涘缓
鏁版嵁搴撶殑涓夊ぇ寮曟搸Innodb銆丮YSIAM銆丮EMARY
鏁版嵁搴撳瓧娈碉細
涓夊ぇ绫伙細
聽 聽 瀛楃涓诧細char銆乿archar銆乴ongtext銆乵ediumtext
聽 聽 鏃ユ湡锛歞ate銆亂ear銆乼ime銆乨atetime銆乼imestamp ...
聽 聽 鏁板�硷細int銆乻mallint銆乼inyint銆乵ediumint
绾︽潫锛�
not null:璁剧疆鍒跺畾鐨勫垪涓嶈兘涓簄ull !=>绌哄瓧绗�
default : 缁欐寚瀹氱殑鍒楄缃竴涓粯璁ゅ��,濡傛灉鎻掑叆鏁版嵁鐨勬椂鍊欎笉缁�
褰撳墠鍒楄缃�硷紝灏变細浣跨敤榛樿鍊硷紝濡傛灉璁剧疆浜嗗�硷紝灏变細浣跨敤璁剧疆鐨勫�笺��
primary key:涓婚敭锛屼笉鑳戒负绌恒�佸敮涓�
unique:鍞竴锛屽彲浠ヤ负null
foreign key:澶栭敭锛屽閿槸鎽镐竴涓〃鐨勪富閿紝涓嶄负null,
鍔犲己琛ㄤ笌琛ㄤ箣闂寸殑鏁版嵁锝岋綁锝侊綆锝橈綁锛堝叧绯伙級
灞炴�э細
auto_increment 鑷:
鍙互鎸囧畾姝ラ暱鍜岃捣濮嬪��
浼氳瘽绾ф闀匡細
set session auto_increment_increment = 姝ラ暱
鍏ㄥ眬鐨勬闀胯缃�:
set global auto_increment_increment = 姝ラ暱
缁欎竴涓〃鎸囧畾涓�涓捣濮嬬殑鑷鐨勫��
ALTER TABLE 琛ㄥ悕 auto_increment = 璧峰鍊�
涓�涓〃閲岄潰鍙兘鏈変竴涓嚜澧烇紝骞朵笖閮芥槸缁欎富閿缃殑銆�
鍒涘缓琛�:
CREATE TABLE 琛ㄥ悕(
聽 聽 瀛楁鍚嶃��绫诲瀷銆�绾︽潫銆�灞炴�� (鑷)锛�
聽 聽 瀛楁鍚嶃��绫诲瀷銆�not null,
聽 聽 瀛楁鍚嶃��绫诲瀷銆�nti null default 榛樿鍊�,
聽 聽 primary key(鍒楀悕)/primary key(鍒楀悕锛屽垪鍚�)
聽 聽 unique key(鍒楀悕)/unique key(鍒楀悕銆佸垪鍚�)
聽 聽 constraint FK_ID foreign key(鍒楀悕)銆�references 涓昏〃(primary key)
)engine=鏁版嵁寮曟搸 default CHARSET=utf8;
淇敼琛�
ALTER TABLE銆�琛ㄥ悕銆�charset= ...
閲嶅懡鍚�
RENAME TABLE 鏃ц〃鍚嶃��TO 鏂拌〃鍚�
淇敼琛ㄥ悕
ALTER TABLE 鏃ц〃鍚嶃��RENAME AS 鏂拌〃鍚�
淇敼琛ㄤ腑鐨勫瓧娈�
ALTER TABLE 琛ㄥ悕銆�change 瀛楁鍚嶃��鏂板瓧娈靛悕銆�绫诲瀷銆�绾︽潫銆�灞炴�э紱
涓嶆敼鍙樻棫瀛楁鍚嶇殑鎯呭喌涓嬩慨鏀�(绫诲瀷銆佺害鏉熺瓑)
ALTER TABLE 琛ㄥ悕銆�change modify 瀛楁鍚� 绫诲瀷銆�绾︽潫銆�灞炴��
娣诲姞鏂扮殑鍒�
ALTER TABLE 琛ㄥ悕銆�ADD 瀛楁鍚嶃��绫诲瀷銆�绾︽潫銆�灞炴��
鍒犻櫎鏌愪竴鍒�
ALTER TABLE 琛ㄥ悕銆�drop 瀛楁鍚�
鍒犻櫎琛�
DROP table 琛ㄥ悕
鍒犻櫎鏁版嵁搴�
DROP DATABASE 鏁版嵁搴撳悕
鏌ョ湅褰撳墠閫夋嫨鐨勬暟鎹簱
select DATABASE()
鍒囨崲鏁版嵁搴�
use 鏁版嵁搴撳悕
澧烇細
鍏ㄥ垪鎻掑叆
insert into tablename values()
闈炲畬鍏ㄦ彃鍏�
insert into tablename() values()
澶氳鎻掑叆
insert into tablename() values(),()
鍒狅細
鍒犻櫎鎸囧畾鏁版嵁
DELETE FROM tablename where 鏉′欢
鍒犻櫎鍏ㄩ儴鏁版嵁
DELETE FROM tablename
鏀癸細
淇敼琛ㄤ腑鏌愪竴鍒楃殑鍏ㄩ儴鍊�(涓嶈杩欎箞鍘诲仛)
UPDATE tablename set 鍒楁槑锛濆��
鏍规嵁鏉′欢淇敼鏁版嵁
UPDATE tablename set 鍒楀悕锛濆�笺��where 鏉′欢
UPDATE tablename set 鍒楀悕锛濆�笺��鍒楀悕锛濆��...where 鏉′欢
鏌ワ細
select * from tablename
select 鍒楋紝鍒楋紝鍒�... from tablename
select * from tablename where 鍒�=鍊�
select * from tablename where 鍒�>鍊�
select * from tablename where 鍒�<鍊�
is null:
select * from tablename where 鍒椼��is null
or:
select * from tablename where銆�鍒�=鍊笺��or 鍒�!=鍊�
in:
select * from tablename where 鍒椼��in (鍊硷紝鍊硷紝鍊�...)
and
select * from tablename where 鍒�=鍊笺��amd 鍒楋紳鍊�
not:
select * from tablename where 鍒� not in(鍊笺�傚�硷紝鍊�...)
select * from tablename where 鍒椼��not is null
between and
select * from tablename where 鍒椼��between 鍊笺��and 鍊�
鎺掑簭
select * from tablename order by 鍒�
select * from tablename order by 鍒� desc
澶氫釜鍒楁帓搴�
select * from tablename order by 鍒� desc,鍒�
鑱氬悎鍑芥暟
count(*):璁$畻鎵�鏈夎
avg():璁$畻鍒楃殑骞冲潎鍊�
sum():姹傚拰锛岃绠楀垪鐨勫�肩殑鍜�
max():璁$畻鍒楃殑鏈�澶у��
min():璁$畻鍒楃殑鏈�灏忓��
閫氶厤绗�
%:鍖归厤浠绘剰瀛楃,浠绘剰娆℃暟
_:鍖归厤浠绘剰瀛楃锛屽繀椤绘湁涓斾粎鏈変竴娆�
涓�鑸窡锛綁锛讥鍖归厤浣跨敤
select 鍒楋紝鍒椼��from tablename where 鍒椼��like '鏉′欢%'
select 鍒楋紝鍒椼��from tablename where 鍒椼��like '鏉′欢_'
python re妯″潡:
complie
match:浠庡紑澶村尮閰嶏紝濡傛灉寮�澶村氨涓嶇鍚堢洿鎺ヨ繑鍥烇籍锝忥綆锝咃紝濡傛灉鍖归厤鍒�
绔嬪嵆杩斿洖缁撴灉锛屽崟娆″尮閰嶏紝鍙栧�间娇鐢╣roup()
search:浠庡ご寮�濮嬪尮閰嶏紝鍦ㄦ暣涓瓧绗︿覆涓煡璇紝鍙鍙堢鍚堣鍒欑殑灏辩珛鍗宠繑鍥�
鍗曡瘝鍖归厤锛屽鏋滄病鏈夌鍚堣鍒欑殑灏辫繑鍥濶one
findall:鍦ㄦ暣涓覆涓紝杩斿洖鎵�鏈夌鍚堣鍒欑殑缁撴灉锛屾槸涓�涓垪琛�
sub:鏇挎崲
split:鍒嗗壊瀛楃涓诧紝杩斿洖鍒楄〃
finditer:璺焒indall鍔熻兘涓�鑷�,杩斿洖缁撴灉鏈夊尯鍒紝杩斿洖鐨勬槸涓�涓彲閫夌殑鍊�
r:鍘熷瀛楃涓�
\:杞箟绗�
琛ㄧ殑璁捐锛�
鑼冨紡锛�
锛憂f锛�
鍒椾笉鍙啀鍒�
2nf:
涓�涓〃蹇呴』瑕佹湁涓�涓富閿紙鍙互鐢卞崟涓垪鎴栧涓垪鏋勬垚锛夛紝闈炰富閿殑鍒楀繀椤诲畬鍏ㄤ緷璧栦簬涓婚敭锛岃�屼笉鏄儴鍒嗕緷璧栦簬涓婚敭
3nf锛�
闈炰富閿殑鍒楋紝蹇呴』鐩存帴渚濊禆涓婚敭锛屼笉鑳藉嚭鐜颁紶閫掑叧绯伙紙闈炰富閿殑鍒桝锛屼緷璧栦笌闈炰富閿殑鍒楋饥锛岄潪涓婚敭鐨勫垪B渚濊禆浜庝富閿級
E-R妯″瀷锛�
E:銆�瀹炰綋锛屼竴涓疄浣撳叾瀹炲氨鏄寚涓�寮犺〃
R:銆�鍏崇郴锛岃〃涓庤〃涔嬮棿涓�涓暟鎹殑鑱旂郴
涓�瀵逛竴锛�
涓�瀵瑰锛�
澶氬澶氾細
鏌ヨ璇彞鐨勯『搴忥細
SELECT銆佸垪锛屽垪銆丗ROM銆佽〃鍚嶃�乄HERE銆佹潯浠躲�丟ROUP BY銆佸垪,鍒椼�丠AVING銆佹潯浠躲�丱RDER BY銆佸垪銆�(ASC|DESC)銆丩IMIT start,count
淇敼琛ㄥ悕锛歛lter table t_book rename to bbb;
娣诲姞鍒楋細alter table 琛ㄥ悕 add column 鍒楀悕 varchar(30);
鍒犻櫎鍒楋細alter table 琛ㄥ悕 drop column 鍒楀悕;
淇敼鍒楀悕MySQL锛� alter table bbb change nnnnn hh int;
淇敼鍒楀悕锛� SQLServer锛歟xec sp_rename't_student.name','nn','column';
淇敼鍒楀悕锛� Oracle锛歭ter table bbb rename column nnnnn to hh int;
淇敼鍒楀睘鎬э細 alter table t_book modify name varchar(22);
淇敼琛細 ALTER TABLE銆�琛ㄥ悕銆�charset= ...