Chinaunix首页 | 论坛 | 博客
  • 博客访问: 711402
  • 博文数量: 147
  • 博客积分: 6010
  • 博客等级: 准将
  • 技术积分: 1725
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-22 10:36
文章分类

全部博文(147)

文章存档

2011年(1)

2010年(1)

2009年(35)

2008年(110)

我的朋友

分类: Mysql/postgreSQL

2008-11-24 19:57:57

使用索引是提高select操作性能的最佳途径
创建索引:
create index username on user(user_name);
查看索引:
show index from table_name;
删除索引:
drop index index_name on table_name


视图是一中虚拟存在的表,并不在数据库中实际存在
创建视图:
create or replace view selectuser as
select user_name from user where user_id=1;
mysql中定义的视图有限制:在from关键字后面不能包含子查询
以下视图不能更新:
包含聚合函数
create or replace view view_name as
select sum(amount) from table_name;
常量视图:
create or replace view pi as select 3.1415 as pi;
select中包含子查询
create view view_name as select (select city from city where city_id=1);
with[cascaded|local]chech option
local:只要满足本视图就可以更新
cascaded:必须满足所有针对该视图的所有视图的条件才可以更新 (默认)
例子:
create or replace view playment_view as
select payment_id,amount from payment
where amount<10 with check option;

create or replace view playment_view1 as
select payment_id,amount from payment_view
where amount>5 with local check option;

create or replace view playment_view2 as
select payment_id,amount from payment_view
where amount>5 with cascaded check option;

update payment_view1 set amount=10 where payment_id=3;正确
update payment_view2 set amount=10 where payment_id=3;错误

查看视图:
show tables;

删除视图:
drop view view_name;


阅读(793) | 评论(0) | 转发(0) |
0

上一篇:选择合适的数据类型

下一篇:触发器

给主人留下些什么吧!~~