MySQL数据库 SQL语句详解
数据库常用操作
操作 | 语句 |
---|---|
创建数据库 | create database if not exists 数据库名; |
查看所有数据库 | show databases; |
切换数据库 | use 数据库名; |
删除数据库 | drop database if exists 数据库名; |
修改数据库编码 | alter database 数据库名 character set utf8; |
表结构常用操作
操作 | 语句 |
---|---|
创建表 | create table if not exists 表名(字段名 数据类型, 字段名 数据类型, ...); |
查看当前数据库所有表 | show tables; |
查看表结构 | desc 表名; |
查看指定表的创建语句 | show create table 表名; |
删除表 | drop table 表名; |
添加列 | alter table 表名 add 列名 数据类型(长度); |
修改列名和类型 | alter table 表名 change 旧列名 新列名数据类型(长度); |
删除列 | alter table 表名 drop 列名; |
修改表名 | rename table 表名 to 新表名; |
增删改
操作 | 语句 |
---|---|
向表中插入列 | insert into 表名(列1, 列2, 列3) values(值1, 值1, 值1), (值2, 值2, 值2); |
向表中所有列插入数据 | insert into 表名 values(值1, 值1, 值1); |
数据修改 | update 表名 set 字段名=值, ... , 字段名=值 where 条件 |
删除表中数据 | delete from 表名 where 条件 |
删除表 | truncate 表名 |
MYSQL约束
操作 | 语句 |
---|---|
主键 | primary key |
删除主键约束 | alter table 表名 drop primary key; |
自增长 | auto_increment |
非空 | not null |
创建表前指定 | create table 表名(id int not null, account varchar(20) not null); |
创建表后指定 | alter table 表名 modify id int not null; |
删除非空约束 | alter table 表名 modify 字段 类型 |
唯一 | unique |
删除唯一约束 | alter table 表名 drop index 唯一约束名 |
默认 | default |
删除默认约束 | alter table 表名 modify 列名 类型 default null |
零填充 | zerofill |
删除零填充约束 | alter table 表名 modify 字段 类型 |
外键 | foreign key |
相关文章
- 学生数据库管理系统
- SpringDataJpa 用MySQL语句怎么分页,spring全家桶SpringDataJpa 用MySQL语句怎么分页
- Docker创建MySQL容器模板命令
- Elasticsearch对应MySQL的对应关系
- 使用SpringDataJpa保存(save)报错误:SQL Error: 1062, SQLState: 23000 控制台会报:Duplicate entry ‘数‘ for key ‘PRIMA
- Navicat Premium 连接sqlserver数据库时提示安装Client失败,解决方案
- Mysql查询当前用户所有数据库语句(SHOW DATABASES)
- MySQL语句-查看当前数据库有哪些表(SHOW TABLES)
- MySQL5.0版本以上新增的 information_schema 数据库是什么?
- MariaDB数据库备份之逻辑备份
- MariaDB数据库创建用户
- MariaDB数据库给用户授权
- MariaDB数据库刷新权限表命令
- MariaDB数据库删除用户命令
- PhpStudy 2016搭建-sqli-libs靶场
- MySQL手动注入步骤
- Pikachu靶场-SQL注入-数字型注入(post)过关步骤
- Pikachu靶场-SQL注入-字符型注入(get)过关步骤
- 利用SQL注入漏洞实现MySQL数据库读写文件
- Kali-工具-sqlmap常见用法