MYSQL对表的增删改查
2025/2/24 8:07:13
来源:https://blog.csdn.net/panpanpan233/article/details/145219975
浏览:
次
关键词:MYSQL对表的增删改查
表的基本操作
- 创建表
create table [if not exists] <tableName> (<columnName> <columnType> [constraints] [comment] , ...<columnName> <columnType> [constraints] [comment]
) ;
- 删除表
drop table [if exists] <tableName> ;
- 修改表结构 alter table
alter table <tableName> add [column] <columnName> <columnType> [constraints] [comment] ;
alter table <tableName> drop [column] <columnName> ;
alter table <tableName> change <oldName> <newName> <columnType> [constraints] [comment] ;
alter table <tableName> modify <columName> <columnType> [constraints] [comment] ;
alter table <tableName> rename to <newTableName> ;rename table <tableName> to <newTableName> ;
- 查看 当前 database 下所有的表
show tables ;
- 查看 表结构
desc <tableName> | describe <tableName> ;
- 查看 建表语句
show create table <tableName> ;