2017年7月4日

Mysql储存过程8:repeat循环

摘要: 语法: 就是相当于其他语言中的: 阅读全文

posted @ 2017-07-04 08:23 Perl6 阅读(1381) 评论(0) 推荐(0) 编辑

Mysql储存过程7: case

摘要: 注意这个case用在储存过程中与用在查询语句中是不一样的。 储存过程中要用end case结束, 用在一般查询中是end结束。 用法可参以参考一下这里: http://www.cnblogs.com/perl6/p/6995593.html 阅读全文

posted @ 2017-07-04 08:02 Perl6 阅读(242) 评论(0) 推荐(0) 编辑

Mysql储存过程6: in / out / inout

摘要: in 为向函数传送进去的值 out 为函数向外返回的值 intout 传送进去的值, 并且还返回这个值 调用时: call q1(1, @value); 注意, 第二个参数要为变量定义的型式。 这个函数并没有向外发送改变后的name值, 所以调用后 select @value 为null。 再看看o 阅读全文

posted @ 2017-07-04 07:43 Perl6 阅读(213) 评论(0) 推荐(0) 编辑

Mysql储存过程5: while

摘要: 循环结构 while create procedure name() begin while 条件 do SQL语句 end while; end$ create procedure aa6() begin declare number int default 0; while number create procedur... 阅读全文

posted @ 2017-07-04 07:15 Perl6 阅读(329) 评论(0) 推荐(0) 编辑

Mysql储存过程4:mysql变量设置

摘要: 默认全局变量是两个@@开头, 可用show variables查看所有默认变量: @@user #declare定义变量只能用在储存过程中 #declare 变量名 数据类型 可选类型 declare num int; declare age int defalut 100; #定义全局变量, 可以 阅读全文

posted @ 2017-07-04 06:49 Perl6 阅读(328) 评论(0) 推荐(0) 编辑

Mysql储存过程3:if语句

摘要: --if/else语句 if 条件 then SQL语句 else SQL语句elseifSQL语句 end if; create procedure test1( number int ) begin if number > 10 then select user(); else select 'please input a number > 10'; ... 阅读全文

posted @ 2017-07-04 06:34 Perl6 阅读(480) 评论(0) 推荐(0) 编辑

Mysql储存过程2:变量定义与参数传递

摘要: #储存过程 中的变量定义 declare 变量名 类型 可选类型 -- 跟建表差不多 create procedure p() begin declare age int default(18); declare number int default 1; select age+number; end$ /* mysql> create procedure p(... 阅读全文

posted @ 2017-07-04 06:26 Perl6 阅读(947) 评论(0) 推荐(0) 编辑

Mysql储存过程1: 设置结束符与储存过程创建

摘要: #显示储存过程 show procedure status; #设置结束符 delimiter $; #创建储存过程 create procedure procedure_name() begin --sql语句 end$ create procedure myshow() begin select 阅读全文

posted @ 2017-07-04 06:14 Perl6 阅读(1231) 评论(0) 推荐(0) 编辑

Mysql中的primary key 与auto_increment

摘要: mysql> create table cc(id int auto_increment); ERROR 1075 (42000): Incorrect table definition; there can be only one auto column and it must be def in 阅读全文

posted @ 2017-07-04 05:25 Perl6 阅读(5795) 评论(1) 推荐(1) 编辑

Mysql中的索引

摘要: 索引: 为了加快查找速度 普通索引: index 唯一索引: unique index 维一索引可以有多个 主键索引: primary key 不能重复 主键必定要维一 一张表上只有一个主键 全文索引: fulltext index 查看索引: show index from table_name; 建立索引: alter table table_name ad... 阅读全文

posted @ 2017-07-04 04:57 Perl6 阅读(238) 评论(0) 推荐(0) 编辑

Mysql备份与恢复

摘要: 备份: 某个库里的所有表: mysqldump -u root -proot dbname > /path/filename.sql 库下面的某个表: mysqldump -u root -proot dbname table1 table2 ...> /path/filename.sql 多个库: mysqldump -u root -proot -B dbname1 dbname2 ... 阅读全文

posted @ 2017-07-04 04:19 Perl6 阅读(129) 评论(0) 推荐(0) 编辑

Mysql中的事务

摘要: 事务: 开启: start transaction; commit提交 rollback 回滚 执行执作前开启 确定无误时, commit提交 每一次commit/rollback后一个事务就算完成了 下次要用还要用start transaction开启 注意, 有一些语句会隐式地提交事务 没有事务时: sql -> 表数据 用事务时: sql -> 事务日志文件 ->... 阅读全文

posted @ 2017-07-04 04:07 Perl6 阅读(174) 评论(0) 推荐(0) 编辑

Msql中的触发器

摘要: 解发器 当执行某种操作时解发的行为。 比如, 当表变动时触发的动作。 像商城订单, 当下单时, 库存减少。 语法: create trigger trigger_name after/befor insert/update/delete on 表名 for each row(这句话固定的) begin sql语句 #一句式多句 end; 单纯触发器执行一条SQL语句, 可以把begi... 阅读全文

posted @ 2017-07-04 03:41 Perl6 阅读(180) 评论(0) 推荐(0) 编辑

mysql中的视图

摘要: #视图创建: create view view_name as select ...... #删除视图: drop view view_name; mysql> create view user as select user,password from mysql.user; Query OK, 0 rows affected (0.03 sec) mysql> select * fr... 阅读全文

posted @ 2017-07-04 02:38 Perl6 阅读(142) 评论(0) 推荐(0) 编辑

导航