在job数据库中有登录用户信息:userlogin表和个人信息:information 表。具体如表结构所示。
create database job;
use job;
create table userlogin(
id int(4) not null unique primary key auto_increment,
name varchar(20) not null,
password varchar(20) not null,
info text
);
create table information(
id int(4) not null primary key unique auto_increment,
name varchar(20) not null,
sex varchar(4) not null,
birthday date,
address varchar(50),
tel varchar(20),
pic blob
);
desc userlogin;
desc information;
请在上述2表上完成如下操作:
1、在name字段创建名为index_name的索引
create index index_name on information (name(10));
2、创建名为index_bir的多列索引
create index index_bir on information (birthday,address);
3、用 ALTER TABLE 语句创建名为index_id的惟一性索引
alter table information add index index_id(id ASC);
4、删除 userlogin 表上的index_ userlogin 索引
create index index_userlogin on userlogin(id(4));
drop index index_userlogin on userlogin;
5、查看 userlogin 表的结构的代码如下:
show create table userlogin \G
6、删除information 表上的index_name索引
drop index index_name on information;
7、查看information 表的结构的语句如下:
show create table information \G
在job数据库中,有聘任人员信息表:Work_lnfo表,其表结构如下表所示:
其中表中练习数据如下:
1,‘张明’,‘男’,19,‘北京市朝阳区’,‘1234567’
2,‘李广’,‘男’,21,‘北京市昌平区’,‘2345678’
3,‘王丹’,‘女’,18,‘湖南省永州市’,‘3456789’
4,‘赵一枚’,‘女’,24,‘浙江宁波市’,‘4567890’
create table work_info(
id int(4) primary key not null unique,
name varchar(20) not null,
sex varchar(4) not null,
age int(4),
address varchar(50),
tel varchar(20)
);
desc work_info;
insert into work_info(id,name,sex,age,address,tel)
values
(1,'张明','男',19,'北京市朝阳区','1234567'),
(2,'李广','男',21,'北京市昌平区','2345678'),
(3,'王丹','女',18,'湖南省永州市','3456789'),
(4,'赵一枚','女',24,'浙江省宁波市','4567890');
//机房:
insert into work_info(id,name,sex,age,address,tel)
values
(1,'ZM','MAN',19,'BJSCYQ','1234567'),
(2,'LG','MAN',21,'BJSCPQ','2345678'),
(3,'WD','NMAN',18,'HNSYZS','3456789'),
(4,'ZYM','NMAN',24,'ZJSNBS','4567890');
select * from work_info;
按照下列要求进行操作:
1.创建视图info_view,显示年龄大于20岁的聘任人员id,name,sex,address信息。
create algorithm=merge view info_view(id,name,sex,address) as
select id,name,sex,address from work_info where age>20 with local check option;
2.查看视图info_view的基本结构和详细结构
查看基本结构的代码如下:
desc info_view;
查看详细结构的代码如下:
show create view info_view \G
3.查看视图info_view的所有记录
select * from info_view;
4.修改视图info_view,满足年龄小于20岁的聘任人员id,name,sex,address信息
alter algorithm=merge view info_view(id,name,sex,address) as
select id,name,sex,address from work_info where age<20 with local check option;
5.更新视图,将id号为3的聘任员的性别,由“男“改为“女”。
update info_view set sex='女' where id=3;
//机房
update info_view set sex='NOMA' where id=3;
6.删除info_view视图
drop view info_view;
在数据库job下创建worklnfo表。创建表的同时在id字段上创建名为index_id的唯一性索引,而且以降序的格式排列。Worklnfo表内容如表所示。
create table workinfo(
id int(4) not null unique primary key auto_increment,
name varchar(20) not null,
type varchar(10),
address varchar(50),
wages year,
contents tinytext,
extra text,
unique index index_id(id desc)
);
请完成如下操作:
1、使用 CREATE INDEX 语句为name字段创建长度为10的索引index_name。
create index index_name on workinfo(name(10));
2、使用 ALTER TABLE 语句在type和address上创建名为index_t的索引。
alter table workinfo add index index_t(type,address);
3、使用 ALTER TABLE 语句将workInfo表的存储引擎更改为MyISAM类型。
alter table workinfo ENGINE=MYISAM;
4、使用 ALTER TABLE 语句在extra字段上创建名为index_ext的全文索引。
alter table workinfo add fulltext index index_ext(extra);
5、使用 DROP 语句删除workInfo表的惟一性索引index_id。
drop index index_id on workinfo;
在学生管理系统中,有学生信息表studentinfo表,其表结构如下:
create table studentinfo(
number int(4) not null primary key unique,
name varchar(20) not null,
major varchar(20),
age int(4)
);
请完成如下操作:
student_num,student_name,student_age,department。
create algorithm=undefined view
college_view(student_num,student_name,student_age,department) as
select number,name,age,major from studentinfo
with local check option;
show create view college_view \G
insert into college_view(student_num,student_name,student_age,department)
values
(0901,'张三',20,'外语'),
(0902,'李四',22,'计算机'),
(0903,'王五',19,'计算机');
create or replace algorithm=undefined view
college_view(student_num,student_name,student_age,department) as
select number,name,age,major
from studentinfo where major='计算机'
with local check option;
drop view college_view;