您的位置:首页 > 数据库 > MySQL

mysql数据库 DDL 数据库定义语言 (下)

2017-04-10 20:46 585 查看
DML (Data Manipulation Language)数据操作语言。

作用:用来操作数据库表中的数据(记录)。

常用的关键字:insert update delete

1.创建数据库

create table 表名(

字段1 字段类型,

字段2 字段类型,

字段3 字段类型,

字段n 字段类型

。。。。。。。

);

create table stu(
id int,
name varchar(20),
gender varchar(5),
birthday date,
address varchar(20)
)


varchar 是设置字符串的最大长度

,但它将多余的空格过过滤了。

2.查看当前数据库中的所有表

show tables;


3.查看表的字段信息

desc + 表名

desc stu;




3.在表中增加列

alter table + 表名 + 新列名 + 数据格式

alter table stu add age int;


4.修改列名

alter table + 表名 + change + 旧列名 + 新列名 + 数据格式

alter table stu change address addre varchar(30);


5.修改列

alter table + 表名 + modify + 列名 + 新的数据格式

alter table stu modify addre varchar(40);


注意:修改列仅仅修改列的数据格式,修改列名不仅修改了字段,也修改了数据格式

6.删除列

alter table + 表名 + drop + 列名

alter table stu drop addre;


7.修改表名

rename table 原来表名 + to + 新表名

raname table stu to stduent;


8.查看创建表的细节

show create table + 表名;

show create table student;


注意:这里和创建数据库的细节差不多

9.修改字符集

alter table + 表名 + character set + 字符集

alter table student character set gbk;


10.删除表

drop + table + 表名

drop table student;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: