操作练习:
- 创建数据库
- 删除数据库
- 修改数据库配置
- 创建数据表
修改表结构
————————————
-
添加字段
-
修改字段
-
重命名字段
-
更改主键
-
删除字段
———————————— -
重命名表名
-
删除表
-
截断表
表数据的操作
- 添加数据
- 修改数据
- 删除数据
代码实现:
1、创建表:
create table student(
stu_no char(12) not null primary key,
stu_name varchar(20) not null,
gender tinyint(1) default 1,
age tinyint(2) not null,
major varchar(20)
);
2、更改主键
alter table student
drop primary key,
add primary key (scores);
2、修改表结构
(1)添加字段
alter table student
add score tinyint(3) not null;
(2)修改字段
alter table student
modify stu_no varchar(12);
(3)更改字段名
alter table studet
change column score scores varchar tinyint(3) primary key;
(4)更改主键
alter table student
drop primary key,
add primary key (scores);
3、重命名表名
rename table student to students;
4、表数据的操作
(1)添加数据
insert into students (stu_no, stu_name, gender, age, major, scores)
values('2018', '小强', 1, 19, '电信', '100');
(2)更改数据
update students set stu_name = '小明' where scores = 100;
(3)删除数据
delete from students where scores = 100;
5、截断表
truncate table students;
6、修改数据库配置
alter database tyrantforever character set 'utf8mb4';
mysqual的使用
1、操作指令:
(1)show databases :显示当前服务下的所有数据库。
(2)use 数据库:使用数据库。
(3)show tables :显出当前数据库下的所有表。
(4)desc 表名:查看表的数据结构。
(5)creat database 数据库名:创建数据库。
(6)drop database 数据库名:删除数据库。
(7)alter database 数据库名 character set ‘uft-8’:修改数据库配置