当前位置:网站首页>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;

边栏推荐
- 题解:在一个排序数组中查找元素第一个和最后一个的位置 (个人笔记)
- [event preview] cloud development, efficient and intelligent - the second Alibaba cloud ECS cloudbuild developer competition is about to start
- Alibaba cloud and Dingjie software released the cloud digital factory solution to realize the localized deployment of cloud MES system
- 【C语言系列】— 一道递归小题目
- 【赛事预告】云上开发,高效智能——第二届阿里云ECS CloudBuild开发者大赛即将启动
- CSDN的md编辑器如何输入上下标?公式和非公式的输入方式不一样
- 冒泡排序 C语言
- Detailed explanation of exit interrupt
- Together with digital people, digital space and XR platform, Alibaba cloud and its partners jointly build a "new vision"
- 刷题狂魔—LeetCode之剑指offer58 - II. 左旋转字符串 详解
猜你喜欢

Alibaba cloud architect details nine trends in the game industry

Vs code的安装步骤及环境配置

Occt learning 003 - MFC single document project

ClickHouse学习(十)监控运行指标

365 day challenge leetcode1000 question - distance between bus stops on day 038 + time-based key value storage + array closest to the target value after transforming the array and + maximum value at t

【C语言系列】— 一道递归小题目

平行云CEO 李岩:CloudXR ,开启通往元宇宙的通道

【C语言系列】— 打印100~200之间的素数

科班同学真的了解未来的职业规划吗?

NVIDIA Zhou Xijian: the last mile from design to digital marketing
随机推荐
水一篇图的拓扑排序
Redirection and files
QML control: combobox
The function of using wechat applet to scan code to log in to the PC web of the system
题解:在一个排序数组中查找元素第一个和最后一个的位置 (个人笔记)
关于局部变量
In depth analysis of common cross end technology stacks of app
指针
【C语言系列】— 一道递归小题目
利用Poi-tl在word模板表格单元格内一次插入多张图片和多行单元格相同数据自动合并的功能组件
【C语言系列】— 不创造第三个变量,实现两个数的交换
More than 200 ISVs have settled in! The first anniversary of Alibaba cloud computing nest
Alibaba cloud and Dingjie software released the cloud digital factory solution to realize the localized deployment of cloud MES system
Day 1
VIM editor use
哈夫曼树以及哈夫曼编码在文件压缩上的应用
JD cloud golden autumn cloud special offer is in progress! Code scanning participation activities
QML custom tabbar
C language file operation
Time complexity and space complexity