当前位置:网站首页>Fundamentals of database operation
Fundamentals of database operation
2022-07-04 10:45:00 【A little boy who studies hard】
Not concluded yet
The database system provides a data definition language (ddl) To define the database schema , And data manipulation language (dml) To express the query and update of the database
Use sql Command to create a database and its tables
- Databases fall into two categories :
1: Relational database mysql、oracle、sql server
2: Non relational database Hbase、readies、mangodb
Create database tables :
create database Library name ( english )
Create table :
create table Table name (< Field name 1>< type 1 >,< Field name 2>< type 2>…)DEFAULT CHARSET=UTF8;
Primary key : Stored values cannot be duplicated , Uniquely identify a row of data
auto_increment: The primary key grows by itself
Insert statement syntax :
insert into Table name values( value , value , value ,…)
Use delete Command to delete tuples from a relationship
delete from
Remove a relationship from the database
drop table
alter table
Additions and deletions :
select sentence
select * from Table name
*: Query all the data
distinct: Forcibly delete duplicates
all To explicitly indicate that duplicates are not removed
where Pretending to allow me to eat only those then form Tuples that satisfy specific predicates in self styled result relationships
where Logical connectives used in Clauses and,or and not, Can contain comparison operators :>,<,<=,>=,=,<>
select A1,A2,A3,A4 Used for the required attributes in the query results
from R1,R2,R3 A list of relationships to be accessed in query evaluation
where P A role again from A predicate on the property of a relation in a clause
Execution order :1:from 2:select 3:where
Natural join : Act on two relationships , And produce a relationship as a result
Update the query statement to display the name statement of the result :
1: Update the queried attribute name to another
select attribute as Alias
from Table name
2: Update the name of the queried table to something else
select attribute
from Table name as Alias , Table name as Alias
effect :
1: Replace long names for easy identification
String operations
SQL Use a pair of single quotation marks to mark the string ,‘ Zhang San ’
Matching strings are case insensitive
You can use like Operator to achieve pattern matching
1: Percent sign %: Match any substring
2: Underline _: Matches any character
3:‘Intro%’: Match any one with Intro The string that begins
4:’%zhangsan%’: Match any package "zhangsan" String of string
5:’—’: Match a three character string
6:’—%’: Matches a string of at least three characters
Example :
select attribute
from Table name
where name like ‘zhangsan’
Arrange the display order of tuples
order by attribute
order by Default ascending order ,desc Descending ,asc Ascending
Example :
select *
from Table name
where Conditions
order by name desc, Birthday asc
between…and replace and
Example :
select *
from Table name
where salary between 10000 and 90000
Check salary at 10000 To 90000 Between people
Two sentences are synonymous
select *
from Table name
where salary >=10000 and salary<= 90000
Set operations
SQL Acting on a relationship union,intersect,except Three
union Union operation
(select *
from student
where year=2009
)
union
(select *
from student
where year=2010
)
Arrange the query results of two query statements vertically with each result as a row
union It has the function of automatically removing duplicates
intersect Cross operation
(select *
from student
where year=2009
)
intersect
(select *
from student
where year=2010
)
Keep the repeated query results
except Difference operation
(select *
from student
where year=2009
)
except
(select *
from student
where year=2010
)
Null value
Aggregation function : With a set of values ( Set or multiset ) For input , A function that returns a single value
avg: Average
min: minimum value
max: Maximum
sum: The sum of the
count: Count : It is often used to calculate the number of tuples in a relationship
SQL You are not allowed to count(*) Use in distinct
Example
select avg( fraction )
from student
select min( fraction )
from student
select max( fraction )
from student
select sum( fraction )
from student
select count(*)
from student
Group aggregation group by: effect : Classify according to the value found in a certain attribute
The key : Anything that doesn't appear in group by If the attribute in clause appears in select Is the wrong statement
having Clause :
having Predicates in Clauses generally work after forming groups
That is to say, it must be generally related to group by A combination of
Example
select name,sex,max(grade)
from student
group by sex
having name
Aggregation of null and Boolean values
Nested subroutine
select-from-where Subroutines are generally nested in where Expression
Database modification
Delete insert update
Delete
delete from surface
where
边栏推荐
- RHCE day 3
- If you don't know these four caching modes, dare you say you understand caching?
- Press the button wizard to learn how to fight monsters - identify the map, run the map, enter the gang and identify NPC
- Tables in the thesis of latex learning
- Introduction to tree and binary tree
- C language - stack
- [Galaxy Kirin V10] [server] KVM create Bridge
- Basic principle of servlet and application of common API methods
- [Galaxy Kirin V10] [server] NFS setup
- Rhcsa - day 13
猜你喜欢
![[Galaxy Kirin V10] [desktop and server] FRP intranet penetration](/img/54/7d1b8b7b8226e2820635dd04b92d1c.jpg)
[Galaxy Kirin V10] [desktop and server] FRP intranet penetration

Three schemes of ZK double machine room

Write a thread pool by hand, and take you to learn the implementation principle of ThreadPoolExecutor thread pool
![[Galaxy Kirin V10] [server] KVM create Bridge](/img/a4/a35a276d13e194cefc547607c59f00.jpg)
[Galaxy Kirin V10] [server] KVM create Bridge
![[Galaxy Kirin V10] [server] set time synchronization of intranet server](/img/f8/0847314029930840c91bce97ccd961.jpg)
[Galaxy Kirin V10] [server] set time synchronization of intranet server

Basic principle of servlet and application of common API methods

Today's sleep quality record 78 points

How do microservices aggregate API documents? This wave of show~

Summary of several job scheduling problems

Idea SSH channel configuration
随机推荐
Add t more space to your computer (no need to add hard disk)
The most detailed teaching -- realize win10 multi-user remote login to intranet machine at the same time -- win10+frp+rdpwrap+ Alibaba cloud server
Es advanced series - 1 JVM memory allocation
/*Rewrite the program, find the value of the element, and return the iterator 9.13: pointing to the found element. Make sure that the program works correctly when the element you are looking for does
Time complexity and space complexity
DCL statement of MySQL Foundation
2、 Operators and branches
2022 ape circle recruitment project (software development)
Write a program to define an array with 10 int elements, and take its position in the array as the initial value of each element.
[Galaxy Kirin V10] [server] FTP introduction and common scenario construction
How do microservices aggregate API documents? This wave of show~
leetcode1-3
For and while loops
Doris / Clickhouse / Hudi, a phased summary in June
Uniapp--- initial use of websocket (long link implementation)
Rhcsa - day 13
The last month before a game goes online
Virtual machine configuration network
[Galaxy Kirin V10] [server] system partition expansion
For programmers, if it hurts the most...