zoukankan      html  css  js  c++  java
  • mysql创建视图

    什么是视图

    视图是数据库中的一个对象,它是数据库管理系统提供给用户的以多种角度观察数据库中数据的一种重要机制。 视图不是数据库中真实的表,而是一张虚拟表,其自身并不存储数据。

    使用视图的优点

    1.集中分散数据

    2.简化查询语句

    3.重用SQL语句

    4.保护数据安全

    5.共享所需数据

    6.更改数据格式

    CREATE TABLE customers(
    cust_id int  NOT NULL AUTO_INCREMENT,
    cust_name CHAR(50) NOT NULL ,
    cust_sex CHAR(1) NOT NULL,
    cust_address CHAR(50) NULL,
    cust_contact CHAR(50) NULL,
    PRIMARY KEY(cust_id)
    );
    
    insert INTO mysql_test.customers
    VALUES(902,'李四','M','武汉','江夏');
    
    insert INTO mysql_test.customers
    VALUES(903,'王五','F','杭州','西湖');
    
    select * from mysql_test.customers
    
    use mysql_test
    /**
    创建视图
    */
    create view mysql_test.customers_view
    as 
    select * from mysql_test.customers
    where cust_sex = 'm' with check option;
    
    /**
    显示视图
    */
    show create view mysql_test.customers_view;
    
    
    /**
    修改视图
    */
    
    alter view mysql_test.customers_view
    as 
    select * from mysql_test.customers
    where cust_sex = 'f' with check option;
    
    /**
    向视图中插入数据
    */
    insert into mysql_test.customers_view
    values (909,'周明','f','武汉','洪山区')
    
    update mysql_test.customers_view
    set cust_address = '上海市'
    
    delete  from mysql_test.customers_view where cust_name = '周明'
    

      

  • 相关阅读:
    居中
    <script type="text/javascript"></script>
    移动端获取全文高度
    video
    transition animation
    移动端隐藏overflow:auto滚轮
    Vue将组件data内的数据重置
    文字刚刚刚刚刚好的居中
    小程序总结(不断更新)
    vue组件之间的传值
  • 原文地址:https://www.cnblogs.com/jacksonxiao/p/11296595.html
Copyright © 2011-2022 走看看