当前位置:网站首页>Database operation day 6
Database operation day 6
2022-07-29 05:33:00 【Xiao Hong is working hard】
List of articles
database :
The data is in memory :
- advantage : Fast reading and writing .
- shortcoming : Program end data loss .
Save the data to a file :
- advantage : Data can be stored permanently .
- shortcoming :1. Frequent IO operation , Low efficiency .
2. Data management is very inconvenient , You need to read all the data as a whole before you can operate .
database :
- Data is permanently stored .
- Easy to manage .
Mysql
One : Database operation :
Create database
CREATE DATABASE school DEFAULT CHARACTER SET UTF8;
- SHOW DATABASES; Show all the databases .

Delete database
DROP DATABASE school;
Two : Operation of database table :
Create table
-- Build table
CREATE TABLE student(
id INT,
`name` CHAR(10),
age INT,
gender CHAR(1)
)
-- Find all tables
SHOW TABLES;

View table structure
-- View table structure
DESC student;

Delete table
-- Delete table
DROP TABLE student;
Change table structure
1. Add fields
-- Add fields
ALTER TABLE student ADD COLUMN address CHAR(255);

2. Modify fields
-- Modify fields
AlTER TABLE student CHANGE address addr char(20);

3. Delete field
-- Delete field
ALTER TABLE student DROP COLUMN addr;

Modify the name of the table
-- Modify the name of the table
ALTER TABLE student RENAME TO teacher;

Add primary key and set self increment :
CREATE TABLE student(
id INT PRIMARY KEY AUTO_INCREMENT,nameCHAR(20),
age INT,
gender char(1)
)
3、 ... and : Basic operation of the watch
1. increase
- 1
-- Insert column ( Insert one at a time )
INSERT INTO student(`name`,age,gender) VALUES(" Zhang San ",1," male ");

- 2
-- Insert column ( Insert more than one at a time )
INSERT INTO student(`name`,age,gender) VALUES(" Li Si ",2," Woman "),(" Wang Wu ",3," male ");

2. Change
-- repair
UPDATE student SET gender=" male " WHERE `name`=" Li Si ";

3. Delete
-- Delete
DELETE FROM student WHERE `name`=" Li Si ";

4. check
SELECT * FROM student;
All the contents of the query table , Not recommended , When the content is small, you can operate , It is suggested that you can find whichever column you need .
- 1
-- Query specified column
SELECT `name`,age,gender FROM student WHERE id=1;

- 2
-- Merge columns when querying , Fields can be treated as java Inside the variable to operate
SELECT id,`name`,(php+java) AS ' Total score ' FROM student;

– Remove duplicate records during query
SELECT DISTINCT address FROM student;Add constant columns when querying , adopt as It's a nickname
SELECT id,name,age AS ‘ Age ’ FROM student;
expand :
1. Aggregate query

2. Query sequence

3. Group query
- 1
-- Group query
-- select The following queries are based on group by After that
SELECT gender,COUNT(id) AS " Number " FROM student GROUP BY gender;

- 2
-- group by The following condition query uses having
SELECT gender,COUNT(id) AS " Number " FROM student GROUP BY gender HAVING COUNT(id)>2;

边栏推荐
- Introduction to array learning simple question sum of two numbers
- CSDN的md编辑器如何输入上下标?公式和非公式的输入方式不一样
- 数组学习之入门简单题 两数之和
- QT series - Installation
- Come on! See how Clickhouse, which has risen 16 places a year, can be implemented in jd.com
- Detailed explanation of GPIO input and output
- 第一周总结
- 终端shell常用命令
- Cryengine Technology
- Helm chart for Kubernetes
猜你喜欢

牛客网编程题—【WY22 Fibonacci数列】和【替换空格】详解

【C语言系列】—深度解剖数据在内存中的存储(二)-浮点型

【剑指offer】— 详解库函数atoi以及模拟实现atoi函数

【C语言系列】—文件操作详解(上)

【C语言系列】—深度解剖数据在内存中的存储(一) 暑假开篇

365 day challenge leetcode 1000 questions - day 037 elements and the maximum side length of squares less than or equal to the threshold + the number of subsequences that meet the conditions

英伟达周锡健:设计到数字营销的最后一公里

三次握手四次挥手针对面试总结

游戏行业弹性计算最佳实践

平行云CEO 李岩:CloudXR ,开启通往元宇宙的通道
随机推荐
重定向和文件
Allocate memory: malloc() and free()
Storage category
存储类别
Come on! See how Clickhouse, which has risen 16 places a year, can be implemented in jd.com
利用Poi-tl在word模板表格单元格内一次插入多张图片和多行单元格相同数据自动合并的功能组件
WDDM learning
ClickHouse学习(十)监控运行指标
【C语言系列】— 不创造第三个变量,实现两个数的交换
Basic principle of recursion
携手数字人、数字空间、XR平台,阿里云与伙伴共同建设“新视界”
Container security open source detection tool - veinmind (mirror backdoor, malicious samples, sensitive information, weak password, etc.)
Live broadcast Preview: integration of JD cloud Devops and jfrog product library
抽象类与接口
C language file operation
The road to success in R & D efficiency of 1000 person Internet companies
【C语言系列】— 把同学弄糊涂的 “常量” 与 “变量”
小程序中的DOM对象元素块动态排序
167. Sum of two numbers II - enter an ordered array
QML type: mousearea