MySQL——数据表基本操作

 1.【新建】create
(1)新建数据库:create database + 数据库名

例:

create database hhy;#创建hhy数据库
show databases;#查看数据库

(2)新建数据表:create table + 数据表名(

        字段名        数据类型,

        字段名        数据类型,

        .......

        字段名        数据类型

        );

例:

create table student(
	id_stu int primary key ,
    stu_name  char(12) not null,
	stu_age int not null);#创建数据表student

#创建一个和student结构相同的数据表:create table 表1 like 表2
create table hhy.st like hhy.stduent;

2.【查看】
(1)查看全部数据表——show tables

 

(2)查看表结构——desc + 数据库.数据表

desc hhy.st;

3.【清空/删除】
(1)清空数据表:truncate table + 数据表

truncate table stduent;#清空数据表中的数据(不影响表结构)

(2)删除数据表:drop table + 数据表

drop table stduent;


(3)删除数据库:drop schema + 数据库名

drop schema hhy;

4.【修改】alter table
(1)修改数据表名称:alter table 原表 rename 修改 

alter table student rename stu;

(2)修改字段类型:alter table 数据表名 modify 字段 改类型

alter table stu modify stu_name varchar(9);

(3)修改字段名称和类型:alter table 数据表名 change 原字段 改字段 改类型

alter table stu change stu_name student_name char(9);

(4)添加字段:alter table 数据表 add 添加字段 enum(' ')

alter table stu add num enum('');

(5)删除字段:alter table 数据表 drop column 删除字段

alter table stu drop column num;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

糯米团子鸭

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值