当前位置:网站首页>MySQL初学者福利
MySQL初学者福利
2022-06-27 17:53:00 【往日如风_】

1、数据库相关操作
1.1、显示数据库
代码:show database;
show和databases之间有一个空格,也可以是多个,但是不能省略 另外SQL不区分大小写
操作实例:
1.2、创建数据库
格式:create database 数据库名;
数据库的名字可以随便起 但是不能是SQL中的关键字 如果实在要使用 就用反引号括起来 反引号在Esc下面 Tab上面
操作实例:
1.3、选中数据库
格式:use 数据库名;
在针对数据库进一步操作之前,需要先选中数据库,再进行操作
实例操作:
1.4、删除数据库
格式:drop database 数据库名:
把数据库删除掉 慎用!!! “从删库,到跑路”
代码示例:
1.5、在cmd中运行MySQL
输入:mysql -u root -p密码
代码示例;
尝试输入上述命令:
show database;
create database 数据库名;
use 数据库名;
drop database 数据库名:
代码示例:
2、数据表
一个数据库中可以有很多数据表
每个数据表可以有很多行,每一行都成为一条"记录"
每一行可以有很多列,每一列称为一个"字段"
MySQL 这样的数据库 每一行中的列都是一致的
假设第一行有三列 那么每一行都有三列
2.1、创建表
操作前先选中要操作的数据库
use student;
在指定列时,列名在前,类型在后 格式:create table 表名(列名 类型,列名 类型…);
代码示例:
不指定要操作的库名时 无法创建
代码示例:
2.2、查看表
格式:show tables;
上述已选中数据库;
代码示例:
代码:show tables;
运行结果:
±------------------+
| Tables_in_student |
±------------------+
| student |
±------------------+
1 row in set (0.00 sec)
2.3、查看表结构
查看某个表里有几列,每一列都是啥类型,每一列啥名字和每一列其他补充信息
格
式:desc 表名; desc<===>describe—描述
代码示例:
Field---->字段 Null当中:
Yes表示这一列允许为空
No表示这一列不允许为空
Default—>默认值
当中的Null 代表字段默认为空
Extra–>额外信息
2.4、练习
有一个商店的数据,记录客户以及购物情况,有以下三个表组成:
商品goods(商品编号goods_id,商品名goods_name, 单价unitprice, 商品类别category, 供
应商provider)
客户customer(客户号customer_id,姓名name,住址address,邮箱email,性别sex,身份证
card_id)
购买purchase(购买订单号order_id,客户号customer_id,商品号goods_id,购买数量nums)
过程描述:
创建数据库

选择数据库

创建数据库表
商品
客户
购买
操作实例:


边栏推荐
- 信息学奥赛一本通 1335:【例2-4】连通块
- 如何利用 RPA 实现自动化获客?
- A simple calculation method of vanishing point
- Is Guosen Securities a state-owned enterprise? Is it safe to open an account with Guosen Securities?
- CDGA|交通行业做好数字化转型的核心是什么?
- 華大單片機KEIL報錯_WEAK的解决方案
- 网络传输是怎么工作的 -- 详解 OSI 模型
- OpenSSL client programming: SSL session failure caused by an obscure function
- 惊呆!原来 markdown 的画图功能如此强大!
- Error reported by Huada MCU Keil_ Weak's solution
猜你喜欢

Redis 原理 - String

“我让这个世界更酷”2022华清远见研发产品发布会圆满成功

拥抱云原生:江苏移动订单中心实践

Usage of rxjs mergemap

Don't worry. This is the truth about wages in all industries in China

Function key input experiment based on stm32f103zet6 Library

在线文本按行批量反转工具

Core dynamic Lianke rushes to the scientific innovation board: with an annual revenue of 170million yuan, Beifang Electronics Institute and Zhongcheng venture capital are shareholders

华大单片机KEIL报错_WEAK的解决方案

今晚战码先锋润和赛道第2期直播丨如何参与OpenHarmony代码贡献
随机推荐
C# 二维码生成、识别,去除白边、任意颜色
判断一个变量是数组还是对象?
高收益银行理财产品在哪里看?
Don't worry. This is the truth about wages in all industries in China
全面解析零知识证明:消解扩容难题 重新定义「隐私安全」
What is ssr/ssg/isr? How do I host them on AWS?
A simple calculation method of vanishing point
Bit. Store: long bear market, stable stacking products may become the main theme
券商经理的开户二维码开户买股票安全吗?有谁知道啊
拥抱云原生:江苏移动订单中心实践
shell脚本常用命令(四)
Informatics Olympiad 1333: [example 2-2] blah data set | openjudge noi 3.4 2729:blah data set
Making single test so simple -- initial experience of Spock framework
Cloud native database: the outlet of the database, you can also take off
Market status and development prospect forecast of the global shuttleless air jet loom industry in 2022
如何利用 RPA 实现自动化获客?
labelimg使用指南
OpenSSL client programming: SSL session failure caused by an obscure function
Erreur Keil de Huada Single Chip Computer La solution de Weak
Tupu digital twin intelligent energy integrated management and control platform