赞
踩
一、实验项目:
索引与视图。
二、实验目的
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;
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。