数据库语句---表操作

mac2024-06-16  54

1.查看表结构

desc 表名

2.创建表结构的语法

create table table_name(字段名 数据类型 可选的约束条件);

demo:创建班级和学生表

create table classes( id int unsigned auto_increment primary key not null, name varchar(10) ); create table students( id int unsigned primary key auto_increment not null, name varchar(20) default '', age tinyint unsigned default 0, height decimal(5,2), gender enum('男','女','人妖','保密'), cls_id int unsigned default 0 )

3.修改表–添加字段

alter table 表名 add 列名 类型 demo:alter table students add birthday datetime;

4.修改表–修改字段–重命名版

alert table 表名 change 原名 新名 类型及约束

demo:alter table syudents change birthday birth datetime not null;

5.修改表–修改字段–不重命名

alter table 表名 modify 列名 类型及约束

demo : alter table students modify birth date nout noll;

6.删除表–删除字段

alter table 表名 drop 列名

demo :alter table students drop birthday;

7.删除表

drop table 表名

demo:drop table students;

8.查看表的创建语句–详细过程

show create table 表名

demo : show create tabele students;

最新回复(0)