DDL 数据定义语⾔总结

一、操作数据库

show(显示数据库)

## 显示当前mysql中的数据库列表
show databases;
## 显示指定数据库
show create database <dbName>;

create(创建数据库)

## 创建数据库
create database <dbName>;
## 创建数据库,当指定名称的数据库不存在时执⾏创建
create database if not exists <dbName>;
## 在创建数据库的同时指定数据库的字符集(字符集:数据存储在数据库中采⽤的编码格式 utf8 gbk)
create database <dbName> character set utf8;

alter(修改字符集)

## 修改数据库的字符集
alter database <dbName> character set utf8; # utf8 gbk

drop(删除数据库)

## 删除数据库
drop database <dbName>;
## 如果数据库存在则删除数据库
drop database is exists <dbName>;

use(使⽤/切换数据库)

use <dbName>

二、操作表

show(显示数据表)

show tables;

creat(创建数据表)

create table students(
 stu_num char(8) not null unique,
 stu_name varchar(20) not null,
 stu_gender char(2) not null,
 stu_age int not null,
 stu_tel char(11) not null unique,
 stu_qq varchar(11) unique
);

drop(删除数据表)

## 删除数据表
drop table <tableName>;
## 当数据表存在时删除数据表
drop table if exists <tableName>;

alter(修改数据表)

## 修改表名
alter table <tableName> rename to <newTableName>;
## 数据表也是有字符集的,默认字符集和数据库⼀致
alter table <tableName> character set utf8;
## 添加列(字段)
alter table <tableName> add <columnName> varchar(200);
## 修改列(字段)的列表和类型
alter table <tableName> change <oldColumnName> <newCloumnName> <type>;
## 只修改列(字段)类型
alter table <tableName> modify <columnName> <newType>;
## 删除列(字段)
alter table stus drop <columnName>;

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值