006_表的CRUD的操作

1. 创建表

1.1. 创建表命令:

create table `表名`(

`列名1` 列的类型(长度) 约束,

`列名2` 列的类型(长度) 约束,

...

) engine=数据库引擎 auto_increment=自动递增起始值 default charset=字符集; 。

1.2. engine数据库引擎一般为InnoDB。

1.3. auto_increment自动递增起始值一般为1。

1.4. default charset默认字符集一般为utf8。

1.6. 表名和列名需要加`符号。

1.7. 创建一个学生表

-- 学生id
-- 姓名name
-- 姓别sex
-- 出生日期birthday
-- 住址address
-- 身高height
-- 体重weight
-- 说明introduce

create table `student` (
`id` bigint(20) not null auto_increment,
`name` varchar(16) default null,
`sex` char(2) default null,
`birthday` datetime default null,
`address` text,
`height` float(16,2) default null,
`weight` double(16,3) default null,
`introduce` longtext,
primary key (`id`)
) engine=InnoDB auto_increment=1 default charset=utf8;

2. 查看表

2.1. 查看所有表命令: show tables; 。

2.2. 查看表结构命令: desc `表名`; 。

2.3. 查看创建表过程命令: show create table `表名`; 。

3. 修改表

3.1. 添加列命令: alter table `表名` add `列名` 列的类型 列的约束; 。

3.2. 修改列命令: alter table `表名` modify `列名` 列的类型 [null/not null | auto_increment | comment | zerofill]; 。

3.3. 修改列名命令: alter table `表名` change `旧列名` `新列名` 列的类型; 。

3.4. 删除列命令: alter table `表名` drop `列名`; 。

3.5. 修改表名命令: rename table `旧表名` to `新表名`; 。

3.6. 修改表的字符集命令: alter table `表名` character set 字符集; 。

4. 删除表

4.1. 删除表命令: drop table `表名`; 。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值