Mysql的常用语句之DDL语句

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/boss_way/article/details/89555191

我也是新手,一起学习,一起进步;【文档内容来自学习的书籍等】

连接数据库

mysql -u用户名 -p

创建数据库

create database 数据库名;

查看数据库

show databases;

使用或切换数据库

use 数据库名;

查看当前数据库的所有表

show tables;

删除数据库,慎用

drop database 数据库名;

创建表

create table 表名(

  name1 type constraints,

  name2 type constraints,

  name3 type constraints

)

查看表结构

desc 表名;

查看表创建的创建语句

show create table 表名;

删除表,谨慎

drop table 表名;

修改字段的类型

alter table 表名 modify 字段 新类型;

增加表字段

alter table 表名  add column 列名 类型 约束;

删除表字段

alter table 表名 drop column 列名;

修改字段名称

alter table 表名 change 旧列名 新列名 新类型;

控制新增的列名在某列之后

alter table 表名 add 新列名 after 旧列名;

修改已存在的列的顺序

alter table 表名 modify 列名 first;

修改表名称

alter table 表名 rename 新表名;
 

猜你喜欢

转载自blog.csdn.net/boss_way/article/details/89555191