MySQL-表的操作:创建表、修改表、删除表

-- 创建表:
-- create table 表名 ();
create table `student` (
    id int,
    name varchar(30),
    math_score int,
    chinese_score int
);


-- 修改表:新增字段
-- alter table 表名 add 字段名 字段类型 after 已存在字段名;
alter table student add english_score int after chinese_score;


-- 修改表:修改字段名称
-- alter table 表名 change 旧字段名 新字段名 类型; 
alter table student change name stu_name varchar(30);


-- 修改表:修改字段类型
-- alter table 表名 modify 字段类型;
alter table student modify id varchar(10);


-- 删除字段:
-- alter table 表名 drop 删除字段名
alter table student drop english_score;


-- 修改表名
-- rename table 表名 to 新表名
rename table student to student_info;


-- 查看表
-- desc 表名
desc student;


-- 删除表
-- drop table 表名
drop table student_info;

 

posted @ 2022-05-17 17:26  柯南同学  阅读(133)  评论(0编辑  收藏  举报