MySQL常用命令(DDL)

1,196 阅读1分钟

MySQL指令基本分为三类:DDL(数据定义语言)、DML(数据操纵语言)、DCL(数据控制语言)。

DDL:DDL指令的功能就是定义数据库DATabase、表table、索引index、视图view、列column等。

DDL与DML的区别就在与DDL是对表进行定义、对结构进行修改,DML只能处理数据库中的数据,不能对表结构进行更改。

关键字有:insert、delete、update、SELECT、drop等,常用DDL语言包括以下:

create database db_name; //定义数据库

create table tb_name( //定义表

id int(5), //定义列

name varchar(10)

);

create view view_name as select id fROMtb_name; //定义视图

如果你在学习C/C++的过程中遇到了问题,可以来加入小编的企鹅圈问小编哦~小编很热情的(●’◡’●)

alter table tb_name add columntexttext [first/after 已存在的列名 ]; //添加一个text列

later table tb_name change 旧列名 新列名 数据类型; //修改表的一个列的列名

alter table tb_name modify 列名 新数据类型; //修改某列的数据类型

alter table tb_name rename 新表名; //修改表的名字

alter table tb_name engine=innoDB/MyISAM... //修改表的存储引擎

alter table tb_name add index idx_name on tb_name(id); //创建普通索引索引idx_name基于id列;

alter table add unique(name); //创建唯一索引name;

alter table add primary key(列名) //添加主键索引

alter table tb_name drop 列名 //删除表的某列

drop index index_name on tb_name; //删除表的某个索引

show index from tb_name; //查看表的索引