• 视图


    视图的优点:集中分散的数据,简化查询语句,重用SQL语句,保护数据安全,共享所需数据,更改数据格式      //视图: 数据库对象

    mysql-> create or replace view mysql_test.cust_view

        ->  as 

        ->  select * from mysql_test.cust

        ->  where cust_sex='M'

        ->  with check option;     //保证今后对该视图的修改都必须符合客户性别为男性这个条件

    mysql-> drop view if exists mysql_test.cust_view

    mysql-> alter view mysql_test.cust_view  //与创建视图只是相差关键字alter

        ->  as 

        ->  select * from mysql_test.cust

        ->  where cust_sex='M'

        ->  with check option;  

    mysql-> show create view mysql_test.cust_view;

    mysql-> insert into mysql_test.cust_view      //使用insert语句通过视图向基本表插入数据 原表会变

        ->  values(909,'周明','M','武汉市','洪山区'); 

    mysql-> update mysql_test.cust_view

        ->  set cust_address='上海市';

    mysql-> delete from mysql_test.cust_view  //牵扯到多表的话,不能用delete语句了

        ->  where cust_name='周明';

    mysql-> select cust_name,cust_address

        ->  from mysql_test.cust_view

        ->  where cust_id  =905;

  • 相关阅读:
    当算法提升到哲学层面—小议验证码识别
    2014总结
    [脚本无敌2]python获取cocos 2dx项目文件列表
    单幅图构建三维图
    [思考]画个圈圈诅咒你
    Mybatis2
    Mybatis1
    淘淘商城虚拟机启动命令
    Zookeeper集群搭建zookeeper01启动不成功解决方案
    Mybatis的xml文件的相关配置
  • 原文地址:https://www.cnblogs.com/lsxsx/p/13388263.html
Copyright © 2020-2023  润新知