mysql视图存储_MySQL的视图和存储

http://www.cnblogs.com/wupeiqi/articles/5713323.html

http://www.cnblogs.com/wupeiqi/articles/5716963.html

1、视图

定义一个名称:

a. 定义对应关系,# 视图--不是真实的表?????

temp1 select * from score where course_id in (1,2)

10道题:

b. 调用temp1

select * from

select * from score where course_id in (1,2)

where xxx

select * from (

select * from score where course_id in (1,2)

) group by

select * from

( select * from score where course_id in (1,2)

) order by

# pymysql

execute('select * from temp1 left join .....')

3、存储过程

c1 =>

select * from temp1 left join .....

# mysql客户端

call c1()

# pymysql

import pymysql

conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='123', db='t1')

cursor = conn.cursor(cursor=pymysql.cursors.DictCursor)

#

# cursor.execute('select * from clasasdfasdfasdfasdfasdfasdfasdfasdfs;')

cursor.callproc('p2')

result = cursor.fetchall()

cursor.close()

conn.close()

2、触发器

a. 为某一个表:

inser 前后

update 前后

delete 前后

b. OLD,NEW

c. 删除多行,插入,更新

for 多行:

OLD,NEW

# 删除之前,讲删除的之添加到另外一张表

delete from tb1 where nid = 1

-- 张二狗 =>tb2

delete from tb1: OLD

-- 张二狗 =>tb2

-- 张三狗 =>tb2

-- 张四狗 =>tb2

-- 张六狗 =>tb2

5、索引

1、视图

a. 临时表

b. 只能查

c. 执行时才获取数据

2、存储过程

a. 可写复杂逻辑

b. 参数:in out inout

c. 结果集:select ...

3、动态SQL

a. sql是字符串

b. 字符串格式化 ? execute proc using @p1

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值