zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    分时区查询问题解决
    .htaccess伪静态实例分享
    net mvc 小目标
    PHP中钩子函数的实现与认识
    session
    修改net基本三层 动软生产
    格式化问题
    数据字典
    关联数据和formatter问题-easyui+微型持久化工具
    说说JSON和JSONP,也许你会豁然开朗
  • 原文地址:https://www.cnblogs.com/xied/p/12506209.html
Copyright © 2011-2022 走看看