MySQL数据库--学习笔记01DDL

DDL【Data Definition Language】数据定义语言,用于定义数据库对象(数据库,表,字段)

1.DDL-数据库操作

查询所有数据库:show databases;
查询当前数据库:select database();
创建: create database [if not exists] 数据库名;
删除: drop database 数据库名;
使用:use 数据库名;

2.DDL-表操作

DDL-表操作-查询

查询当前数据库所有表:show tables;
查询表结构:desc 表名;
查询指定表的建表语句:show create table 表名;

DDL-表操作-创建

create table 表名(字段 字段类型[comment 字段注释],字段 字段类型);

例:

create table rep(  
    -> id int comment '编号',
    -> name varchar(50) comment '姓名',
    -> age int comment '年龄',
    -> gender varchar(1) comment '性别'
    -> )comment '用户表';

DDL-表操作-修改

添加字段
alter table 表名 add 字段名 类型(长度)[comment 注释][约束];
修改数据类型 
alter table 表名 modify 字段名 新数据类型(长度);
修改字段名和字段类型
alter table 表名 change 旧字段名 新字段名 类型(长度)[comment 注释][约束];

删除字段
alter table 表名 drop 字段名;

修改表名
alter table 表名 rename to新表名;

DDL-表操作-删除

删除表
drop table [if exists] 表名;
删除指定表,并重新创建该表
truncate table 表名;

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值