<5>mysql:数据表操作
表操作
命令 | 作用 |
---|---|
show tables [like <expression>]; | 查看当前数据库中所有的表 |
create table [if not exists] <tbname>(<column> <type> <constraint>, ...); | 创建表 |
create table [if not exists] <tbname> as <tbname>; | 复制表 |
truncate table [if exists] <tbname>; | 删除表数据 |
drop table [if exists] <tbname>; | 删除表 |
alter table [if exists] <tbname> <alter content>; | 修改表结构 |
describe/desc [if exists] <tbname>; | 查看表结构 |
说明
命令 | 作用 |
---|---|
like <expression> | 使用模糊匹配,过滤数据库 |
if not exists | 数据库不存在时,才进行操作 |
if exists | 数据库存在时,才进行操作 |
type | 数据类型,见下方type说明 |
constraint | 数据类型,跳转详细说明 |
alter content | 表修改内容,见下方alter content说明 |
type
数据类型 | 说明 |
---|---|
int | 整型 |
float | 浮点型 |
numeric(n,s) | 浮点型,n-总长度,s-小数长度 |
decimal(n,s) | 浮点型,n-总长度,s-小数长度 |
char(n) | 定长字符型,n-长度 |
varchar(n) | 可变长字符型,n-长度 |
alter content
alter content | 说明 |
---|---|
add <column> <type> <constraint> | 增加字段 |
modify <column> <type> | 修改字段数据类型 |
modify <column> <type> first | 修改字段位置为第一个 |
modify <column> <type> after <column> | 修改字段位置为目标字段后面 |
change <column> <name> <type> | 修改字段名称、类型 |
rename <dbname> | 修改表名 |
drop <column> | 删除字段 |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· Vue3状态管理终极指南:Pinia保姆级教程