码迷,mamicode.com
首页 > 数据库 > 详细

兄弟连(python)---------mysql日常随笔

时间:2017-12-12 21:26:02      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:lib   改变   触发器   call   含义   cal   python   invalid   表名   

  1. 创建视图

 

mysql> create view v1 as select * from t2;

Query OK, 0 rows affected (0.02 sec)

 

删除主表的时候 那么视图表就不起作用了

mysql> drop table t2;

Query OK, 0 rows affected (0.02 sec)

 

mysql> select * from v1;

ERROR 1356 (HY000): View ‘python.v1‘ references invalid table(s) or column(s) or function(s) or definer/invoker of view

mysql> show tables;

 

删除视图表

mysql> drop view v1;

Query OK, 0 rows affected (0.00 sec)

 

  1. MySQL内部函数

mysql> select ucase(‘name‘) from stu;  -----这个含义是让字符串name变成大写而不是让name字段里面所有的值变成大写

+---------------+

| ucase(‘name‘) |

+---------------+

| NAME          |

| NAME          |

| NAME          |

 

mysql> select ucase(name) from stu; -----这个含义是 让name字段里面的所有值变成大写

+------------------+

| ucase(name)      |

+------------------+

|                  |

| 22WEW            |

| 666              |

| AA               |

| AABB             |

| CAO              |

| EEE              |

 

  1. 命名别名

mysql> select length(‘dsjfkdsfiefuie‘);

如果不起别名的话那么现实出来的字段名就是你查询出来的名字

+--------------------------+

| length(‘dsjfkdsfiefuie‘) |

+--------------------------+

|             14 |

+--------------------------+

1 row in set (0.00 sec)

 

如果你起了别名,那么现实出来的名字就是你的别名

mysql> select length(‘dsfdsfdsfds‘) as len;

+-----+

| len |

+-----+

|  11 |

+-----+

1 row in set (0.00 sec)

 

给表名起一个别名  使用as

mysql> select a.name,c.childname from type as a,typechild as c where a.id = c.pid;

不使用 as

mysql> select a.name,c.childname from type a,typechild c where a.id = c.pid;

 

  1. MySQL预处理操作

mysql> prepare stmt from ‘select * from stu where id > ?‘

Query OK, 0 rows affected (0.01 sec)

Statement prepared

 

mysql> set @id = 5;

Query OK, 0 rows affected (0.00 sec)

 

mysql> execute stmt using @id;

+----+------------------+-----+-----+----------+

| id | name             | age | sex | classid  |

+----+------------------+-----+-----+----------+

|  7 | uu03             |  26 | m   | lamp103  |

|  8 | uu04             |  27 | w   | lamp105  |

 

  1. 存储过程  ????? mysql命令行中字符串和变量使用什么符号链接   +

mysql> create procedure intos(num int)

    -> begin

    -> set @i = 0;

    -> while @i <= num do

    -> insert into t3 values (2,‘we232‘);

    -> set @i = @i+1;

    -> end while;

    -> end#

Query OK, 0 rows affected (0.00 sec)

 

mysql> call intos(10)#

Query OK, 0 rows affected (0.04 sec)

 

  1. trigger触发器

 

创建触发器 tg5

mysql> create trigger tg5 after insert on t4 for each row

    -> begin

    -> update t5 set name=‘bbbb‘ where id = 2;

    -> end#

Query OK, 0 rows affected (0.02 sec)

 

mysql> select * from t5#

+----+--------+

| id | name   |

+----+--------+

|  1 | aaaa   |

|  2 | ????   |

|  3 | 我很你 |

+----+--------+

3 rows in set (0.00 sec)

 

t4表中插入数据的时候要改变t5表的信息

mysql> insert into t4(id,name) values (9,‘wew23232‘)#

Query OK, 1 row affected (0.02 sec)

 

mysql> select * from t5#

+----+--------+

| id | name   |

+----+--------+

|  1 | aaaa   |

|  2 | bbbb   |

|  3 | 我很你 |

+----+--------+

3 rows in set (0.00 sec)

兄弟连(python)---------mysql日常随笔

标签:lib   改变   触发器   call   含义   cal   python   invalid   表名   

原文地址:http://www.cnblogs.com/hao-jiang-tao/p/8028900.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!