当前位置:网站首页>Sister Juan takes you to learn database -- 5-day sprint Day1
Sister Juan takes you to learn database -- 5-day sprint Day1
2022-06-29 18:12:00 【Hua Weiyun】
Blog home page : The blog home page of Beijing and JIUPU
Welcome to pay attention to the likes and comments
This article is original by Beijing and JIUPU ,csdn First episode !
Series column :java Study
Reference Online Course : Silicon Valley
Starting time :2022 year 5 month 31 Japan
You do march and April , There will be an answer in August and September , Come on
If you think the blogger's article is good , Please support the blogger for the third company
Last words , The author is a newcomer , Not doing well in many ways , Welcome the boss to correct , Study together , To rush
picture
Navigation assistant
Book girl takes you to learn database ---5 Sky sprint Day1 Navigation assistant 🥩1 Database Overview 2 What is? SQL8 mysql Common commands 9 Understanding of table full name Gender Age ( Column : Field ) 10 SQL classification 14 Simple query Note that :select and from It's all keywords . Field names and table names are identifiers .22 Conditions of the query
🥩1 Database Overview
What is a database ? What is database management system ? What is? SQL? What is the relationship between them ?
database : English words DataBase, abbreviation DB. A combination of files that store data in a certain format . seeing the name of a thing one thinks of its function : A warehouse for storing data , It's actually a bunch of files . These files store data in a specific format . Database management system :DataBaseManagement, abbreviation DBMS. Database management system is specially used to manage the data in the database , The database management system can add, delete, modify and check the data in the database . Common database management system :MySQL、Oracle、MS SqlServer、DB2、sybase etc. ....
2 What is? SQL
Programmers need to learn SQL sentence , Programmers write SQL sentence , then DBMS Responsible for the execution of SQL sentence , Finally to complete the database of data addition, deletion, modification and query operation .SQL It's a set of standards , What programmers mainly learn is SQL sentence , This SQL stay mysql Can be used in , At the same time Oracle Can also be used in , stay DB2 Can also be used in .
The relationship between the three ?DBMS-- perform --> SQL -- operation --> DB
First install the database management system MySQL, Then learn SQL How to write sentences , To write SQL After statement ,DBMS Yes SQL Statement to execute , Finally to complete the database data management .
8 mysql Common commands
sign out mysql :exit;
see mysql Which databases are in : show databases; # Be careful : It ends with a semicolon , A semicolon is a semicolon in English .mysql> show databases;+--------------------+| Database |+--------------------+| information_schema || mysql || performance_schema || test |+--------------------+mysql By default, it comes with 4 A database . Choose to use a database :mysql> use test;Database changed Indicates that you are using a name called test The database of .
Create database :mysql> create database bjpowernode;Query OK, 1 row affected (0.00 sec)mysql> show databases;+--------------------+| Database |+--------------------+| information_schema || bjpowernode || mysql || performance_schema || test |+--------------------+ Check which tables are under a database :mysql> show tables;
see mysql Version number of the database :mysql> select version();+-----------+| version() |+-----------+| 5.5.36 |+-----------+ Check which database you are currently using :mysql> select database();+-------------+| database() |+-------------+| bjpowernode |+-------------+
Import the data prepared in advance :bjpowernode.sql In this file are the database tables prepared for the exercise . How to sql Data import in file mysql> source D:\course\03-MySQL\document\bjpowernode.sql # Be careful : No Chinese in the path !!!!
View the structure of the table :mysql> desc dept; # describe Abbreviation for :desc+--------+-------------+------+-----+---------+-------+| Field | Type | Null | Key | Default | Extra |+--------+-------------+------+-----+---------+-------+| DEPTNO | int(2) | NO | PRI | NULL | | Department number | DNAME | varchar(14) | YES | | NULL | | Department name | LOC | varchar(13) | YES | | NULL | | Location +--------+-------------+------+-----+---------+-------+
9 Understanding of table
The most basic unit in the database is the table :table
What is a watch table? Why use tables to store data ?
full name Gender Age ( Column : Field )
Zhang San male 20 -------> That's ok ( Record ) Li Si Woman 21 -------> That's ok ( Record ) Wang Wu male 22 -------> That's ok ( Record )
The data in the database is represented in the form of tables . Because the table is more intuitive .
Any table has rows and columns : That's ok (row): It's called data / Record . Column (column): It's called a field . Name field 、 Gender field 、 Age field .
Get to know : Every field has : Field name 、 data type 、 Constraints, etc . The field name is understandable , It's an ordinary name , Just see the name and know the meaning . data type : character string , Numbers , Date, etc. , Later talk . constraint : There are also many constraints , One of them is called uniqueness constraint , After this constraint is added , The data in this field cannot be repeated .
10 SQL classification
SQL There are many sentences , It's best to classify , It's easier to remember . It is divided into :DQL: Data query language ( Usually with select Keywords are all query statements )select...
DML: Data operation language ( All additions, deletions and modifications to the data in the table are DML)insert delete updateinsert increase delete Delete update Change This is mainly the data in the operation table data.
DDL: Data definition language Usually with create、drop、alter The are DDL.DDL The main operation is the structure of the table . Not the data in the table .create: newly build , Equivalent to increase drop: Delete alter: modify This addition, deletion, modification and DML Different , This is mainly used to operate the table structure .
TCL: Is a transaction control language Include : Transaction submission :commit; Transaction rollback :rollback;
DCL: Is a data control language . for example : to grant authorization grant、 Revoke authority revoke....
14 Simple query
Query a field ?select Field name from Table name ;
Note that :select and from It's all keywords .
Field names and table names are identifiers .
emphasize : about SQL The statement is , It's universal , be-all SQL Statement to “;” ending . in addition SQL Statement is case insensitive , Will do .
Query two fields , Or multiple fields are separated by commas “,” Query department number and department name select deptno,dname from dept; +--------+------------+ | deptno | dname | +--------+------------+ | 10 | ACCOUNTING | | 20 | RESEARCH | | 30 | SALES | | 40 | OPERATIONS | +--------+------------+ Query all fields The first way : You can write each field select a,b,c,d,e,f... from tablename;
The second way : have access to *select * from dept;+--------+------------+----------+| DEPTNO | DNAME | LOC |+--------+------------+----------+ | 10 | ACCOUNTING | NEW YORK | | 20 | RESEARCH | DALLAS | | 30 | SALES | CHICAGO | | 40 | OPERATIONS | BOSTON | +--------+------------+----------+
Disadvantages of this approach : 1、 Low efficiency 2、 Poor readability . In actual development, it is not recommended that , You can play by yourself. No problem . You can DOS You can use this method to quickly look at the full table data in the command window .Alias the columns of the query : Use as Keywords are aliased . mysql> select deptno,dname as deptname from dept; +--------+------------+ | deptno | deptname | +--------+------------+ | 10 | ACCOUNTING | | 20 | RESEARCH | | 30 | SALES | | 40 | OPERATIONS | +--------+------------+ Be careful : Just display the query result column name as deptname, The original table column name is still called :dname remember :select Statement will never be modified .( Because it is only responsible for querying )
as Can keywords be omitted ? Tolerable mysql> select deptno,dname deptname from dept; Let's assume that when you use an alias , There are spaces in the alias , What do I do ? select deptno,dname 'dept name' from dept; // Charizing Operator select deptno,dname "dept name" from dept; // quotation marks +--------+------------+ | deptno | dept name | +--------+------------+ | 10 | ACCOUNTING | | 20 | RESEARCH | | 30 | SALES | | 40 | OPERATIONS | +--------+------------+ Be careful : In all databases , Strings are uniformly enclosed in single quotes , Single quotation marks are standard , Double quotation marks in oracle Not in the database . But in mysql Can be used in .
22 Conditions of the query
Conditions of the query Conditions of the query : Not all the data in the table are found out . It is found that the qualified .
Query syntax format : select Field 1, Field 2, Field 3.... from Table name where Conditions ; What are the conditions ?= be equal to Query salary equals 800 Employee's name and number ? select empno,ename from emp where sal = 800; Inquire about SMITH Your number and salary ? select empno,sal from emp where ename = 'SMITH'; // String using single quotes
<> or != It's not equal to Query salary is not equal to 800 Employee's name and number ? select empno,ename from emp where sal != 800; select empno,ename from emp where sal <> 800; // An unequal sign consisting of the less than sign and the greater than sign
< Less than Query salary less than 2000 Employee's name and number ? mysql> select empno,ename,sal from emp where sal < 2000; +-------+--------+---------+ | empno | ename | sal | +-------+--------+---------+ | 7369 | SMITH | 800.00 | | 7499 | ALLEN | 1600.00 | | 7521 | WARD | 1250.00 | +-------+--------+---------+
<= Less than or equal to Query salary less than or equal to 3000 Employee's name and number ? select empno,ename,sal from emp where sal <= 3000;
Greater than Query salary greater than 3000 Employee's name and number ?select empno,ename,sal from emp where sal > 3000;
= Greater than or equal to Query salary greater than or equal to 3000 Employee's name and number ?select empno,ename,sal from emp where sal >= 3000;
between … and …. Between two values , Equate to >= and <= Query salary in 2450 and 3000 Employee information between ? Include 2450 and 3000 The first way :>= and <= (and Is and means .) select empno,ename,sal from emp where sal >= 2450 and sal <= 3000; +-------+-------+---------+ | empno | ename | sal | +-------+-------+---------+ | 7566 | JONES | 2975.00 | | 7698 | BLAKE | 2850.00 | | 7782 | CLARK | 2450.00 | | 7788 | SCOTT | 3000.00 | | 7902 | FORD | 3000.00 | +-------+-------+---------+ The second way :between … and … select empno,ename,sal from emp where sal between 2450 and 3000;
Be careful : Use between and When , We must follow the principle of "small left and big right" . between and It's a closed interval , Include values at both ends .
is null by null(is not null Not empty ) Be careful : In the database null You can't use the equal sign to measure . Need to use is null Because in the database null Means nothing , It's not a value , So you can't use the equal sign to measure .
and also
or perhaps
and and or At the same time , Is there a priority problem ?and and or At the same time ,and High priority . If you want to let or Execute first , Need to add “ parentheses ”. Later in development , If you're not sure about priorities , Just add parentheses .
in contain , It's equivalent to more than one or (not in Not in this range )
not You can take non , Mainly used in is or in in
like It is called fuzzy query , Support % Or underline match
% Match any number of characters
# Underline : Any character .
#(% It's a special symbol ,_ It is also a special symbol )
Find the name to T At the end of the ? select ename from emp where ename like '%T';
Find the name to K At the beginning ? select ename from emp where ename like 'K%';
Find out the second word each is A Of ? select ename from emp where ename like '_A%';
Find out that the third letter is R Of ?
边栏推荐
- If the evaluation conclusion of waiting insurance is poor, does it mean that waiting insurance has been done in vain?
- Test dble split function execution + import time-consuming shell script reference
- Automatic software test - read SMS verification code using SMS transponder and selenium
- Xiaomai technology x hologres: high availability of real-time data warehouse construction of ten billion level advertising
- VB. Net read / write NFC ntag tag source code
- Adobe Premiere基礎-聲音調整(音量矯正,降噪,電話音,音高換擋器,參數均衡器)(十八)
- 让 Google 搜索到自己的博客
- [tcapulusdb knowledge base] tcapulusdb doc acceptance - Introduction to creating game area
- PostgreSQL database system table
- JS merge two 2D arrays and remove the same items (collation)
猜你喜欢

布隆过滤器:

Have you grasped the most frequently asked question in the interview about massive data processing?

Selenium upload file

VB. Net read / write NFC ntag tag source code

两种Controller层接口鉴权方式

Parental delegation mechanism

Analyze the implementation principle of zero copy mechanism, applicable scenarios and code implementation

Adobe Premiere Basics - general operations for editing material files (offline files, replacing materials, material labels and grouping, material enabling, convenient adjustment of opacity, project pa

Spingmvc requests and responses

Xiaobai yuesai 51 supplement e g f
随机推荐
面试中问最常问的海量数据处理你拿捏了没?
Record that the server has been invaded by viruses: the SSH password has been changed, the login fails, the malicious program runs full of CPU, the jar package fails to start automatically, and you ha
【TcaplusDB知识库】TcaplusDB单据受理-创建业务介绍
Request header field xxxx is not allowed by Access-Control-Allow-Headers in preflight response问题
MaxCompute Studio
最受欢迎的30款开源软件
MaxCompute字符串替换函数-replace
Application and practice of DDD in domestic hotel transaction -- Theory
[target tracking] |stark configuration win OTB
Automatic software test - read SMS verification code using SMS transponder and selenium
Mysql database daily backup and scheduled cleanup script
VB. Net read / write NFC ntag tag source code
Configure the local domain name through the hosts file
Visio标注、批注位置
Shell tutorial circular statements for, while, until usage
Precondition end of script headers or end of script output before headers
My first experience of remote office | community essay solicitation
Xiaobai yuesai 51 supplement e g f
DevCloud加持下的青软,让教育“智”上云端
/usr/bin/ld: warning: **libmysqlclient.so.20**, needed by //usr/