当前位置:网站首页>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 ?
边栏推荐
- 牛客小Bai月赛52 D 环上食虫(尺取+st表)
- The soft youth under the blessing of devcloud makes education "smart" in the cloud
- Goldfish rhca memoirs: do447 building advanced job workflow -- using fact cache to improve performance
- [tcapulusdb knowledge base] tcapulusdb system user group introduction
- 布隆过滤器:
- Lodash deep copy usage
- MySql存储过程循环的使用分析详解
- EasyCVR部署服务器集群时,出现一台在线一台不在线是什么原因?
- JS merge two one-dimensional arrays and remove the same items (collation)
- Detailed analysis on the use of MySQL stored procedure loop
猜你喜欢
Precondition end of script headers or end of script output before headers
Professor of Cambridge University: eating breakfast often is harmful and dangerous. - you know what
Detailed analysis on the use of MySQL stored procedure loop
Wechat applet development reserve knowledge
ISO 32000-2 international standard 7.7
Software testing - you may not understand the basic theoretical knowledge
Abc253 D fizzbuzz sum hard (tolerance exclusion theorem)
VB. Net read / write NFC ntag tag source code
js两个二维数组合并并去除相同项(整理)
Adobe Premiere Basics - common video effects (corner positioning, mosaic, blur, sharpen, handwriting tools, effect control hierarchy) (16)
随机推荐
Premature end of script headers 或 End of script output before headers
EasyCVR部署服务器集群时,出现一台在线一台不在线是什么原因?
3H proficient in opencv (IX) - the simplest face detection
金鱼哥RHCA回忆录:DO447构建高级作业工作流--创建作业模板调查以设置工作的变量
mac安装php7.2
ISO 32000-2 international standard 7.7
Spingmvc requests and responses
Niuke small Bai monthly race 52 D ring insectivorous (feet +st table)
【TcaplusDB知识库】TcaplusDB单据受理-事务执行介绍
3h精通OpenCV(八)-形状检测
[webdriver] upload files using AutoIT
Adobe Premiere基础-常用的视频特效(裁剪,黑白,剪辑速度,镜像,镜头光晕)(十五)
双亲委派机制
VMware installation esxi
[tcapulusdb knowledge base] tcapulusdb doc acceptance - transaction execution introduction
【TcaplusDB知识库】TcaplusDB单据受理-创建业务介绍
Adobe Premiere基础-炫酷文字快闪(十四)
ABC253 D FizzBuzz Sum Hard(容斥定理)
Mongotemplate - distinct use
mysql — 清空表中数据