当前位置:网站首页>二、MySQL数据库基础
二、MySQL数据库基础
2022-07-25 04:08:00 【龙文章.】
一、谨慎删库!
数据库存储在硬盘上,操作系统为了方便进行管理,把整个硬盘分成了若干个“盘块”,每个盘块都可以保存一定的数据,每个文件,实际上可能是由一个或者多个盘块上面的数据来构成的,当操作系统删除文件时,为了提高删除动作,在删除的时候并不是真的把硬盘上之前保存的数据擦除掉,而只是把文件对应的模块,标记为“无效状态”,因此一旦出现误删库的情况,就要让主机尽快断电,就避免操作系统把这些被标记为无效状态的分块分配出去
二、MySQL的数据类型
MySQL是一个“关系型数据库”
特点就是通过表的形式来组织的数据
1、数值类型(整数+小数)
M和D描述了小数的精度
M表示整个数字的有效数字位数不超过M
D表示整个数字小数点后的位数不超过D
DEClMAL相比于FLOAT和DOUBLE可以更精确的表示小数
DECIMAL相当于通过字符串的方式来表示浮点数,优势就是能够精确表示,精确计算,劣势就是计算时候消耗时间更多,存储空间也更多,除非是特别需要,才考虑使用DECIMAL
2、字符串类型
varchar()最常用的类型
3、时间日期

推荐使用8字节版本
4、最常用的类型
int
bigint
double
decimal
varchar
datetime
三、数据库的表操作
1、创建表
create table 表名(列名 类型,列名 类型.....);
️注意:
1、同一个数据库中,不能有两个表的名字相同
2、创建表的时候,表名或者列名,不能和SQL的关键字冲突
解决方法:
2、查看有哪些表
在选中数据库的前提下
使用show tables;来查看有哪些表

3、查看表结构
desc查看这个表里面的列和类型
desc 表名
desc => describe
Field:每一列都是一个字段,所以Field表示表这里有几列
Type: 字段类型,varchar(20)约束存储的时候最多存20个字符
NULL: 这一列是否允许为空
Default:默认值,此处默认的默认值为空(NULL),也能手动修改默认值
4、删除表
drop table 表名;

小练习
有一个商店的数据,商品goods(商品编号goods_id,商品名goods_name,单价umitprice,商品类别category,供应商provider)创建一个数据库
四、小技巧
1、MySQL多行编辑容易出错,可以用编辑器将SQL写好,然后复制粘贴过去
SQL这样就是保留下来的,未来迁移数据库非常方便
2、算钱的时候用double不精确,可以使用int代替小数,把价格的单位视为分,相当于把小数转化成整数了
边栏推荐
- Network engineering case: integrated network design of CII company
- 很清晰的条理
- 数据中台建设(一):数据中台出现的背景
- LVGL 8.2 Textarea
- C language: Escape Character
- C language: string processing function
- Press the switch for the minimum number of times to turn on all lights
- The application could not be installed: INSTALL_ FAILED_ USER_ RESTRICTED
- Permanently solve Matplotlib Chinese garbled code
- 运筹学基础【一】 之 导论
猜你喜欢

开源之夏专访|“00 后” PMC member 白泽平

Preparation for Android development in big companies

Paper:《Peeking Inside the Black Box: Visualizing Statistical Learning with Plots of Individual Condi

Simple understanding of RPC

Cannot make qopenglcontext current in a different thread: the solution to pyqt multithread crash

Spire. Office for net 7.7.2 and news

Druid连接池——从0开始坚强的一点点的自学,Druid一点不懂的可以点进来,懂得别点进来,点进来你会嫌我啰嗦的

Press the switch for the minimum number of times to turn on all lights

Swagger simple quick start tutorial

Es- retrieve the selected field from the search
随机推荐
The latest Matlab download and installation tutorial (with files)
LVGL 8.2 Slider
Numpy overview
Roleapp focuses on Web3 and opens the door of Web3 with the key of "data can be held"
GBase JDBC 连接数据库异常
GDT,LDT,GDTR,LDTR
Project launch process of software testing technology
Infinite connection · infinite collaboration | the first global enterprise communication cloud conference WECC is coming
@ResponseBody注解的总结
What is behind the development of science and technology now is the advent of the era of the meta universe
Sudden! Britain accuses Huawei of major defects in its equipment (with report)
一般在进行数仓迁移过程中,是如何进行数据测试的?
Cannot make qopenglcontext current in a different thread: the solution to pyqt multithread crash
Beijing University of Posts and telecommunications | RIS assisted in-house multi robot communication system joint deep reinforcement learning
How many rows does PostgreSQL need to partition for each table?
看问题的角度
What are the models of asemi from the manufacturer of rectifier bridge and how about the electroplating process of the manufacturer of rectifier bridge?
Metinfo function public function getcity() error: XXX function no permission load!!!
暗黑王者|ZEGO 低照度图像增强技术解析
How to use ide tool hhdbcs to create a data table containing 1000 simulated data in Oracle database, and