【数据库】数据库基本操作

操作练习:

  • 创建数据库
  • 删除数据库
  • 修改数据库配置
  • 创建数据表

修改表结构
————————————

  • 添加字段

  • 修改字段

  • 重命名字段

  • 更改主键

  • 删除字段
    ————————————

  • 重命名表名

  • 删除表

  • 截断表

表数据的操作

  • 添加数据
  • 修改数据
  • 删除数据

代码实现:
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’:修改数据库配置

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值