当前位置:网站首页>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
边栏推荐
- /*Write a loop to output the elements of the list container in reverse order*/
- /*Write a function to open the file for input, read the contents of the file into the vector container of string class 8.9: type, and store each line as an element of the container object*/
- VI text editor and user rights management, group management and time management
- If the uniapp is less than 1000, it will be displayed according to the original number. If the number exceeds 1000, it will be converted into 10w+ 1.3k+ display
- Does any teacher know how to inherit richsourcefunction custom reading Mysql to do increment?
- Using Lua to realize 99 multiplication table
- Realsense of d435i, d435, d415, t265_ Matching and installation of viewer environment
- Introduction to tree and binary tree
- Latex error: missing delimiter (. Inserted) {\xi \left( {p,{p_q}} \right)} \right|}}
- Delayed message center design
猜你喜欢
The bamboo shadow sweeps the steps, the dust does not move, and the moon passes through the marsh without trace -- in-depth understanding of the pointer
VI text editor and user rights management, group management and time management
MPLS: multi protocol label switching
Evolution from monomer architecture to microservice architecture
[Galaxy Kirin V10] [desktop] printer
Collection of practical string functions
Delayed message center design
Dynamic memory management
Use the data to tell you where is the most difficult province for the college entrance examination!
[Galaxy Kirin V10] [desktop and server] FRP intranet penetration
随机推荐
Dynamic memory management
Doris / Clickhouse / Hudi, a phased summary in June
Static comprehensive experiment ---hcip1
Rhcsa12
Today's sleep quality record 78 points
TS type gymnastics: illustrating a complex advanced type
Press the button wizard to learn how to fight monsters - identify the map, run the map, enter the gang and identify NPC
Does any teacher know how to inherit richsourcefunction custom reading Mysql to do increment?
BGP advanced experiment
如果不知道這4種緩存模式,敢說懂緩存嗎?
RHCE - day one
Day06 list job
PHP code audit 3 - system reload vulnerability
[Galaxy Kirin V10] [server] grub default password
/*The rewriter outputs the contents of the IA array. It is required that the type defined by typedef cannot be used in the outer loop*/
PHP programming language (1) - operators
Three schemes of ZK double machine room
Learning XML DOM -- a typical model for parsing XML documents
DDL statement of MySQL Foundation
20 minutes to learn what XML is_ XML learning notes_ What is an XML file_ Basic grammatical rules_ How to parse