SQL中的视图,索引

SQL中的视图,索引
 
视图
--------------------------------------------------------------
创建视图
CREATE VIEW  
[ < 数据库名 > .] [ < 所有者 > .]
    视图名 [ ( 列名 [ ,...n ] ) ]
   [ WITH < 视图属性 > [ ,...n ] ] AS 子查询
删除视图
DROP VIEW {视图名} [,…n]
 
例子:
    create view V_S as select sno,sname,sex from s where age>20
    create view v_grade As Select s.sno,s.sname,c.cname,sc.grade
        From s,c,sc Where s.sno=sc.sno and c.cno=sc.cno and sno='20030001'
 
使用视图
    1.    使用视图插入表数据
        Insert into v_s
        Values ('20050009','李华',19,'男')
    2.    使用视图修改表数据
        例:update v_s
        Set sex='女'
        Where sno='20040001'
    3.    使用视图删除表数据
         例:delete v_s
        Where sno='20040001'
 
        
索引
--------------------------------------------------------------
包括:
    1.聚集索引和非聚集索引
    2.复合索引
    3.唯一索引
创建索引
    CREATE [UNIQUE] [CLUSTERED│[NONCLUSTERED] ]INDEX 索引名  
        ON {表名|视图} (列名 [[ASC]│DESC] [,…n])
        
例1:为表jbxx创建一个非聚集索引,索引字段为employee_name,索引名为i_employeename
    create index i_employeename on jbxx(employee_name)
例2:新建一个表,名称为temp,为此表创建一个惟一聚集索引,索引字段为temp_number,索引名为i_temp_number。
    use student
    Create table t_temp(
        temp_number int,
        temp_name char(10),
        temp_age int
    )
    create unique clustered index i_temp_number on t_temp(temp_number)
例3:为表s创建一个复合索引,使用sex和birthday字段。
    Use student Create index i_s on s(sex,birthday)
 
删除索引句法:
    drop index 'table.index│view.index'[,…n]
    例,drop index s.i_s_sexandbirth
 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值