数据库(3)

视图

视图的规则和限制

  • 与表一样,视图必须唯一命名
  • 对于创建视图的数目没有限制
  • 可以创建视图,但必须具有足够的访问权限
  • 视图可以嵌套 即可以利用从其他视图中检索数据的查询来构造一个视图
  • order by可以用在视图中,如果从该视图检索数据select中也含有order by 那么该视图中的order by将被覆盖
  • 视图不能索引,
  • 视图可以和表一起使用

创建视图

  • create view productcustomers as select cust_name,cust_contact,prod_id from customers,orders,orderitems where customers.cust_id = orders.cust_id and orderitems.order_num = orders.order_num;
  • select cust_name,cust_contact from productcustomers where prop_id=’TNT2’;
  • 视图大大简化了复杂sql语句的使用,利用视图,可以一次性编写基础的sql,然后根绝需要多次使用

更新视图

  • 并非所有视图都是可更新的,如果视图中有以下操作,是不能更新的
  • 分组
  • 联结
  • 子查询
  • 聚集函数
  • DINSTINCT
  • 导出列

数据库维护

  • 备份数据

索引的类型

  • 普通索引
  • 唯一索引(索引列的值必须唯一 允许有空值)
  • 主键索引(不允许为空)
  • 组合索引

猜你喜欢

转载自blog.csdn.net/wlm_suzhou/article/details/78193199