環境:win7 64位、mysql
適合閱讀者:對sql基本語法有一定了解
<建表語句>:
create table <表名>(
<列名> <類型> <列級約束>[,<列名> <類型> <列級約束>]...
[,<表級約束>]
);
<類型>:int | char | date |....
<列級約束>:[not ]null | default <默認值> | primary key | auto_increment | comment '注釋內容' | unique | check(<布爾表達式>) | enum('string',...) | ...
<表級約束>:primary key(<列名>[,<列名>]...) , foreign key(<列名>[,<列名>]... ) references <表名> (<列名>[,<列名>]...) , with check option
<創建視圖語句>:
create view as <視圖名><查詢語句>;
create view(<列名>[,<列名>]...) as <查詢語句>;
<復合查詢語句>:<查詢語句>[union|intersect|except][ all]<查詢語句>;
<嵌套查詢語句>:<查詢語句>(<查詢語句>);
<查詢語句>:
select *|<列名>{,<列明>}
from <表明>{<表名>}
[where <條件語句>]
[Group by <列名> [having <分組條件語句>]]
[Order By <列名2>[ asc | desc ]];
[語句]: 空|語句
{語句}: 空|語句[,語句]···
<name>: <數據庫名>|<表名>|<列名>
<[distinct ]name[ 別名]>:可以給name消重或指定別名
<條件語句>:<列名>|<函數> <謂詞><條件>
<謂詞>:
比較 =, >, <, >=, <=, !=, <>, !>, !< not + 上述比較運算符(例如not=)
確定范圍 between and, not between and
確定集合 in, not in
字符匹配 like, not like
空值 is null, is not null
多重條件 and, or
其它 not exists, exists, any, all
<drop語句>:drop table|index|view <表名>|<索引名>|<視圖名>
<grant語句>:grant <權限>[,<權限>]… on <對象類型> <對象名> to <用戶>[,<用戶> …] [with grant option];
<權限>:SELECT, INSERT, UPDATE(<列名>[,<列名>]...), DELETE, ALL PRIVIEGES, ALTER,INDEX, CREATETAB, CONNECT
<用戶>:用戶名@登錄主機 identified by "密碼"|public
<revoke語句>:revoke <權限>[,<權限>]… on <對象類型> <對象名> from <用戶>[,<用戶> …]
參考:教學課件