创建数据库day1db字符集utf8并使用
create database day1db default charset utf8;
创建t_hero表,有name字段字符集utf8
create table t_hero (name char)charset=utf8;
修改表名为hero
alter table t_hero rename hero;
最后面添加价格字段money,最前面添加id字段, name后面添加age字段
alter table hero add money int(4);
alter table table hero add id int(5) FIRST;
alter table hero add age tinyint after name;
表中添加以下数据:1,李白,50,6888 2,赵云,30,13888 3,刘备,25,6888
insert into hero values("1","李白","50","6888"),("2","赵云","30","13888"),("3","刘备","25","6888");
修改刘备年龄为52岁
update hero set age="52" where name="刘备";
修改年龄小于等于50岁的价格为5000
update hero set money="5000" where age<="50";
删除价格为5000的信息
delete from hero where money="5000";
删除表,删除数据库
drop table hero;drop database day1db;
综合练习题2、
创建数据库newdb1,字符集utf8并使用
create database newdb1 charset=utf8;
use newdb1;
在数据库中创建员工表emp字段id,name,sal(工资),deptld(部门id)字符集utf8
create table emp(id varchar(8),name varchar(8),sal char(9),deptld char(20))charset=utf8;
创建部门表dept字段id,name,loc(部门地址)字符集utf8
create table dept(id varchar(8),name varchar(8),sal char(9))charset=utf8;
部门表插入一下数据1.神仙部 天庭 2.妖怪部 盘丝洞
insert into dept values("1","神仙部","天庭"),("2","妖怪部","盘丝洞");
员工表插入1.悟空 5000 1,2 八戒 2000 1, 3 蜘蛛精 8000 2, 4 白骨精 9000 2
insert into emp values("1","悟空","5000","1"),("2","八戒","2000","1"),("3","蜘蛛精","8000","2"),("4","白骨精","9000","2");
查询工资6000一下的员工姓名和工资
select name,sal from emp where sal<"6000";
修改神仙部的名字为取经部
update dept set name="取经部" where name="神仙部";
给员工添加奖金comm字段
alter table emp add comm char(20);
修改员工表中部门id为1的奖金为500
update emp set comm ="500" where id="1";
把取经部门的地址改成五台山
update dept set loc ="五台山" where name="取经部";
修改奖金字段为性别gender字段 类型为varchar
alter table emp change comm gender varchar;
修改孙悟空和猪八戒性别为男
update emp set gender="男" where name="悟空";
update emp set gender="男" where name="八戒";
删除没有性别的员工(null不能用=要用is)
delete from emp where gender="is no";
删除性别字段
alter table emp drop gender;
删除表和删除数据库
drop table emp;
drop table dept;drop database newdb1;
下一篇:Java_封装