环境:
=========================================================================
第一题
(1)
创建表
create table pet( name varchar(20) not null comment '宠物名称', owner varchar(20) comment '宠物主人', species varchar(20) not null comment '种类', sex char not null comment '性别', birth year not null comment '出生日期', death year comment '死亡日
期' );
向表中插入数据
insert into
pet(name,owner,species,sex,birth,death) values
("Fluffy","Harold","cat","f",2003,2010),
("Claws","Gwen","cat","m",2004,NULL),
("Buffy",NULL,"dog","f",2009,NULL),
("Fang","Benny","dog","m",2000,NULL),
("Bowser","Diane","dog","m",2003,2009),
("Chirpy",NULL,"bird","f",2008,NULL);
注意:name字段定义的时候是varchar,所以插入的时候要用引号
(2)
update pet set owner="Kevin" where name="Fang";
(3)
update pet set owner="Duck" where owner is NULL;
(4)
delete from pet where death is not null;
(5)
delete from pet;
=========================================================================
第二题
1
create table employee(
id int(100) primary key auto_increment comment '员工编号',
name varchar(10) comment '员工姓名',
gender enum('男','女') comment '员工性别',
salary varchar(10) comment '员工薪水'
);
2
insert into employee(name,gender,salary) values
('张三','男','2000'),
('李四','男','1000'),
('王五','女','4000');
3.修改表数据
3.1 将所有员工薪水修改为5000元
update employee set salary='5000';
3.2将姓名为张三的员工薪水修改为3000元
update employee set salary='3000' where name='张三';
3.3将姓名为李四的员工薪水修改为4000元,gener改为女
update employee set salary='4000' ,gender='女' where name='李四';
3.4 将王五的薪水在原有基础上增加1000元
update employee set salary=salary+1000 where name='王五';