SQL中表删除与表修改

表删表

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;
相关推荐
卤炖阑尾炎9 分钟前
PostgreSQL 日常运维全指南:从基础操作到备份恢复
运维·数据库·postgresql
daad7771 小时前
wifi_note
运维·服务器·数据库
xixingzhe22 小时前
Mysql统计空间增量
数据库·mysql
程序员萌萌2 小时前
Redis的缓存机制和淘汰策略详解
数据库·redis·缓存机制·淘汰策略
不剪发的Tony老师3 小时前
SQLite 3.53.0版本发布,重要更新
数据库·sqlite
Bczheng13 小时前
九.Berkeley DB数据库 序列化和钱包管理(1)
数据库
cozil3 小时前
记录mysql创建数据库未指定字符集引发的问题及解决方法
数据库·mysql
架构师老Y3 小时前
013、数据库性能优化:索引、查询与连接池
数据库·python·oracle·性能优化·架构
AC赳赳老秦3 小时前
OpenClaw数据库高效操作指南:MySQL/PostgreSQL批量处理与数据迁移实战
大数据·数据库·mysql·elasticsearch·postgresql·deepseek·openclaw
一 乐3 小时前
校园线上招聘|基于springboot + vue校园线上招聘系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·论文·毕设·校园线上招聘系统