第1关:建立索引
任务描述
任务: 第一题 在jdxx数据表根据省份sf、城市cs、区县qx和名称name建立主索引zsy 第二题 在jdxx数据表根据名称name建立普通索引namesy
use province;
#代码开始
alter table jdxx add constraint zsy primary key(sf,cs,qx,name);
create index namesy on jdxx(name);
#代码结束
show index in jdxx\g;
第2关:建立视图并更新视图
任务描述
本关任务: 建立视图csxx,显示jdxx数据表的cs长沙市的区县qx、名称mc。 根据视图csxx,将开福区qx的西湖街道name修改为月湖街道
use province;
#代码开始
create or replace view csxx as select qx,name from jdxx where cs='长沙市';
update csxx set name = '月湖街道' where qx='开福区' and name = '西湖街道';
#代码结束
select * from csxx;
第3关:建立基于多表的视图
任务描述
本关任务:建立基于多表的视图
任务要求
根据province数据表和qxyzbm数据表 建立视图csbm 视图中有长沙市的区县qx、名称name和区县编码qxbm字段
use province
#代码开始
create or replace view csbm as select jdxx.qx,name,qxbm from jdxx,qxyzbm
where jdxx.qx=qxyzbm.qx and jdxx.cs ='长沙市';
#代码结束
select * from csbm;