当前位置:   article > 正文

实验3 索引与视图_实验三索引和视图

实验三索引和视图

一、实验项目:

索引与视图。

实验目的

1、能够使用SQL语句创建和删除各类索引。

2、能够使用SQL语句创建、修改、删除和查看视图。

3、能够使用SQL语句进行视图的查询和更新操作

实验内容

使用SQL语句完成下列题目。

1、对account表中的fullname和address列创建复合索引C_fa_ind。

2、对product表中的name列前4个字符创建唯一性索引U_na_ind。

3、创建视图account_v1,包含所有男客户的客户编号、姓名、密码、性别、电话和家庭住址,字段名用中文表示,同时要求对视图的修改也符合上述条件。

4、从account_v1查询家住“深圳市”的客户信息。

5、创建视图Orders_v2,包含订单编号、客户姓名、地址、订单日期和订单总额。

6、从Orders_v2查询2023年的订单。

7、创建视图lineitem_v3,包含商品名称、定购日期、定购数量和单价。

8、从account_v1插入一条记录:(u0007,张华,123456,男,13901234567)。

9、将Orders_v2中订单号为20230411的订单总价加200元。

10、删除视图account_v1中客户号为u0006的客户。

四、实验参考代码

1、create index C_fa_ind on account(fullname,address);

   Show index from account;

2、create unique index U_na_ind on product(name(4));

   Show index from product;

3、create view account_v1

As select userid as '客户编号' ,fullname as '姓名',password as '密码',sex as '性别',phone as '电话',address as '家庭住址'

from account

where sex='男'

with check option;

或者

create view account_v1(客户编号,姓名,密码,性别,电话,家庭住址)

as select userid,fullname,password,sex,phone,address

from account

where sex='男'

with check option;

desc account_v1;

4、select *

from account_v1

where 家庭住址 like "%深圳市%";

5、create view Orders_v2

as

select orders.orderid,account.fullname,address,orderdate,totalprice

from orders,account

where orders.userid=account.userid;

desc orders_v2;

6、select *

from Orders_v2

where orderdate like "2023%";

7、create view lineitem_v3

as

select name,orderdate,quantity,unitprice

from product,orders,lineitem

where product.productid=lineitem.productid and lineitem.orderid=orders.orderid;

desc lineitem_v3;

8、insert into account_v1

values('u0007','张华','123456','男','13901234567',null);

插入前:select * from account_v1;

插入后:select * from account_v1;

9、update Orders_v2

set totalprice=totalprice+200

where orderid=20230411;

修改前:select * from orders_v2 where orderid=20230411;

修改后:select * from orders_v2 where orderid=20230411;

10、delete from account_v1

where 客户编号='u0006';

删除前:select * from account_v1;

删除后:select * from account_v1;

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/906113?site
推荐阅读
相关标签
  

闽ICP备14008679号