欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 明星 > Mysql(一) - 数据库操作, 表操作, CRUD

Mysql(一) - 数据库操作, 表操作, CRUD

2025/4/3 5:24:28 来源:https://blog.csdn.net/nmbg11/article/details/141827065  浏览:    关键词:Mysql(一) - 数据库操作, 表操作, CRUD

目录

一.数据库操作

1.增加数据库 

 2.展示数据库

3.删除数据库

4.选定数据库

二.表操作

1.增加选定数据库中的表

2.展示选定数据库中的表

3.删除选定数据库中表

4.查看选定表的字段信息

三.增加和查找

1.增加

 2.查找

a.where的使用

b.分页查询

四.更新和删除

1. 更新

2.删除


一.数据库操作

1.增加数据库 

create database if not exists database_name;

 2.展示数据库

show databases;

3.删除数据库

4.选定数据库

use database_name;


二.表操作

1.增加选定数据库中的表

create table if not exists table_name( 字段 数据类型, ...);

2.展示选定数据库中的表

show tables;

3.删除选定数据库中表

drop table is exists table_name;

4.查看选定表的字段信息

desc (describe) table_name;


三.增加和查找

Mysql中的四个基础操作-C(create 增加), R(retrieve 查找), U(update 更新), D(delete 删除).

1.增加

insert into table_name (字段, ...) value/values (值, ...) ;

 2.查找

select distinct 字段 as new_name, ... from table_name order by 指定字段 asc/desc(descend);

distinct: 去重

as: 起别名

order by 字段 asc/desc: 根据指定字段进行升序或降序排列

a.where的使用

where搭配条件来使用.

= 等于   != 不等于   > < 大于小于   <=> 用来和NULL比较

is null   is not null

between s and e 区间查询   in(v1, v2, ...) 区间查询

% 匹配多个字符   _ 匹配一个字符

and   or   not 与或非

b.分页查询

select 字段, ... from table_name limit n;

select 字段, ... form table_name limit s, n;

select 字段, ... from table_name limit n offset s;

四.更新和删除

1. 更新

update table_name set 列名 = ?, ..;

2.删除

delete from table_name where ? order by 字段 asc/desc limit n offset s;

 

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词