MySQL数据库实验四 MySQL索引与视图 |
您所在的位置:网站首页 › 数量account › MySQL数据库实验四 MySQL索引与视图 |
一、实验项目: MySQL索引与视图。 二、实验目的 1、掌握MySQL索引的创建和删除操作。 2、掌握视图的创建和删除操作。 3、掌握视图的更新方法。 三、实验内容 1、对account表中的fullname和address列创建复合索引C_fa_ind。 create index C_fa_ind on account(fullname,address);2、对product表中的name列前4个字符创建唯一性索引U_na_ind。 create unique index U_na_ind on product(name(4));3、创建视图account_v1,包含所有男客户的客户编号、姓名、密码、性别、电话和家庭住址,字段名用中文表示,同时要求对视图的修改也符合上述条件。 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;4、从account_v1查询家住“深圳市”的客户信息。 select * from account_v1 where 家庭住址 like "%深圳市%";5、创建视图Orders_v2,包含订单编号、客户姓名、地址、订单日期和订单总额。 create view Orders_v2 as select orders.orderid,account.fullname,address,orderdate,totalprice from orders,account where orders.userid=account.userid;6、从Orders_v2查询2013年的订单。 select * from Orders_v2 where orderdate like "2013%";7、创建视图lineitem_v3,包含商品名称、定购日期、定购数量和单价。 create view lineitem_v3 as select name,orderdate,quantity,listprice from product,orders,lineitem where product.productid=lineitem.productid and lineitem.orderid=orders.orderid;8、从account_v1插入一条记录:(u0007,张华,123456,男,13901234567)。 insert into account_v1 values('u0007','张华','123456','男','13901234567',null);9、将Orders_v2中订单号为20130411的订单总价加200元。 update Orders_v2 set totalprice=totalprice+200 where orderid='20130411';10、删除视图account_v1中客户号为u0006的客户。 delete from account_v1 where 客户编号='u0006'; |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |