mysql语法结构

环境: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 <用户>[,<用户> …]


 

参考:教学课件

原文地址:https://www.cnblogs.com/woxinfeixiang2015/p/5509250.html