当前位置:网站首页>Mysql操作数据库
Mysql操作数据库
2022-06-26 06:42:00 【我的天才女友】
创建表
- 创建数据表
create table (if not exists) 表名(
字段, 数据类型 约束条件
---
[表约束条件]
)
create table t_goods(
id INT,
t_cate varchar(30),
t_remake varchar(100)
);
- 查看表
show tables

- 指定主键 PRIMARY_KEY
单个主键
create table t_goods(
id INT PRIMARY_KEY,
t_cate varchar(30),
t_remake varchar(100)
);
单个主键
create table t_goods(
id INT ,
t_cate varchar(30),
t_remake varchar(100),
PRIMARY_KEY(id, t_cate)
);
- 外键
create table t_goods(
id INT ,
t_cate varchar(30),
t_remake varchar(100),
constraint 外键名 foreign key(字段) references 表(字段)
);
- 非空字段
NOT NULL
- 默认值
default
- 自动递增
auto_increment - 指定存储引擎
create table t_goods(
id INT ,
t_cate varchar(30),
t_remake varchar(100)
) engine=InnoDB default charset set utf8mb4 collate utf8mb4_0900_ai_ci;
查看表
describe 对应表明可以查看对应的表信息,也可以使用 show create table + 表名 查看对应的表结构。
describe --

修改数据表
- 修改数据表名称
alter table A RENAME to B
- 添加字段
alter table A add COLUMN 列约束 First/after 字段
- 修改字段名称
alter table 表名 CHANGE 字段 新字段 新字段属性
- 修改字段的数据类型
alter table 表名 modify 字段 字段属性 字段位置
- 删除字段
alter table 表名 drop 字段
- 修改引擎
alter table 表名 ENGINE=引擎名称
- 删除外键
alter table 表名 drop foreign key --
删除数据表
drop table if exists 表名
临时表
临时表创建的时候多一个TEMPORARY即可
create TEMPORARY table if not exists 表名
边栏推荐
- Go language learning notes 1.2- variables
- Differences, advantages and disadvantages between synchronous communication and asynchronous communication
- New generation engineers teach you how to play with alluxio + ml (Part 1)
- STM 32 使用cube 生成TIM触发ADC并通过DMA传输的问题
- Show statement usage supplement
- 分析 NFT 项目的 5 个指标
- Typescript type
- Decompile Android applications, interview Android
- 视图简析
- Container with the most water
猜你喜欢

直播预告丨消防安全讲师培训“云课堂”即将开讲!

Decompile Android applications, interview Android

I use flask to write the website "II"

C nuget offline cache package installation

Phantom star VR equipment product details II: dark battlefield

Closure problem C Lua

Pytorch uses multi GPU parallel training and its principle and precautions

On a classical problem

LabVIEW Arduino tcp/ip remote smart home system (project part-5)

If you meet a female driver who drives didi as an amateur, you can earn 500 yuan a day!
随机推荐
Unsatisfied dependency expressed through field ‘baseMapper‘; nested exceptio
Reasons why MySQL indexes are not effective
Guide to "avoid dismissal during probation period"
Gof23 - builder mode
Past events of Xinhua III
[golang] time related
MySQL基础用法01
遇到女司机业余开滴滴,日入500!
Distribution operation of D
宝塔服务器搭建及数据库远程连接
自顶向下的变成方法
Number of connections server database message: error number 2003can't connect to MySQL server on 'server address' (10061)
China micronutrient market trend report, technical innovation and market forecast
I use flask to write the website "II"
Screen sharing recommendations
3.pyinstaller模块介绍
MySQL delete in without index
Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource could
淺析一道經典題
浏览器的四大内核:Trident,Gecko,Webkit,Blink