表删表
sql
drop table [if not exist] students;
表修改
ALTER语句
使用 ALTER TABLE 语句追加, 修改, 或删除列的语法
add
增加字段:
sql
alter table students add [column] dateT date;
设置默认值:
sql
alter table students add dateT date DEFAULT "2025-12-12";
modify
注意:MODIFY 后必须明确指定「字段类型」(哪怕只是修改注释,也要重新声明类型)
修改字段类型,属性:
sql
alter table students modify dataT datetime;
alter table students modify dateT date comment "日期";
修改字段默认不为空:
sql
alter table students modify stu_id int not null;
修改字段默认可以为空:
sql
alter table students modify stu_id int default null;
drop
删除字段:
sql
alter table students drop length;
其他写法:
sql
drop table table_name
change
修改字段名称:
sql
alter table students character set utf8;
character set
修改表的字符集:
sql
alter table students character set utf8;
rename to
修改表名
sql
alter table students rename to student;
其他写法:
sql
rename table students to student;