重点: 1,基本SQL语句 2,连表 一对多 多对多 3,存储过程 4,动态执行SQL 5, 函数 6,视图,触发器 ----------------------------Mysql基本操作---------------------------- create----创造 defalut----默认 ---------------例 create table tb1(nid int not null defalut 2,num int not null) drop----放弃;停止 删除表 ---------------例 drop table 表名 alter----改变 改变表 ---------------例 alter table 表名 add 列名 类型 (添加列) column----专栏;圆柱;纵队,列 ---------------例 alter table 表名 drop column 列名(删除列) modify----修改;被修饰 ---------------例 alter table 表名 modify column 列名 类型; -- 类型(修改列) change----改变,变更;交换 ---------------例 alter table 表名 change 原列名 新列名 类型; -- 列名,类型(修改列) primary----首要的,主要的 ---------------例 alter table 表名 add primary key(列名);(添加主键) ---------------例 alter table 表名 drop primary key;(删除主键) ---------------例 alter table 表名 modify 列名 int, drop primary key;(删除主键) constraint----约束;限制;强制 foreign----外国的 外 references----参考引用 ---------------例 alter table 从表 add constraint 外键名称(形如:FK_从表_主表) foreign key 从表(外键字段) references 主表(主键字段);(添加外键) ---------------例 alter table 表名 drop foreign key 外键名称(删除外键) default----设置默认值 ---------------例 alter table 表 alter 列 set default 1000;(修改默认值) ---------------例 alter table 表 alter 列 drop default (删除默认值) insert----插入 into----方向 ---------------例 insert into 表 (列名,列名...) values (值,值,值...) delete----删除 清空表 ---------------例 delete from 表 where id=1 and name=‘alex‘ update----更新 ---------------例 update 表 set name = ‘alex‘ where id>1 select----挑选出来的 ---------------例 select * from 表 where id > 1 like----类似的 喜欢的 ---------------例 select * from 表 where name like ‘ale%‘ - ale开头的所有(多个字符串) limit----限制 ---------------例 select * from 表 limit 4,5; - 从第4行开始的5行 order----要求 命令 秩序 ---------------例 select * from 表 order by 列 asc - 根据 “列” 从小到大排列 group----组 group by----分组依据 ---------------例 select num from 表 group by num 分组 having----所有的 ---------------例 select num from 表 group by num having max(id) > 10 union----同盟,联盟;协会,工会;联合,团结 ---------------例 select 列1 from 表1 union select 列2 from 表2(组合查看,自动处理重合) ---------------例 select 列1 from 表1 union all select 列2 from 表2(组合查看,不处理重合) http://www.cnblogs.com/cloniu/p/6393588.html ----------------------------存储过程---------------------------- procedures 程序---创建函数 exists 存在---判断条件中使用 declare 声明---声明变量 default 默认---默认值设置 delimiter 定界符 向服务器说明以什么结束 then 然后---多个语句判断添加 http://www.cnblogs.com/cloniu/p/6396904.html ----------------------------动态执行sql语---------------------------- prepare 准备 using 使用 deallocate 释放 execute 执行 http://www.cnblogs.com/cloniu/p/6400238.html ----------------------------
原文:http://www.cnblogs.com/cloniu/p/6400562.html