当前位置:网站首页>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
边栏推荐
- Latex learning insertion number - list of filled dots, bars, numbers
- Sword finger offer 31 Stack push in and pop-up sequence
- Hidden C2 tunnel -- use of icmpsh of ICMP
- DNS hijacking
- Four characteristics and isolation levels of database transactions
- /*Write a loop to output the elements of the list container in reverse order*/
- 【Day2】 convolutional-neural-networks
- Safety reinforcement learning based on linear function approximation safe RL with linear function approximation translation 2
- [test theory] test phase analysis (unit, integration, system test)
- Latex error: missing delimiter (. Inserted) {\xi \left( {p,{p_q}} \right)} \right|}}
猜你喜欢
Software sharing: the best PDF document conversion tool and PDF Suite Enterprise version sharing | with sharing
Delayed message center design
shell awk
Basic data types of MySQL
Linked list operation can never change without its roots
DCL statement of MySQL Foundation
Rhcsa12
Online troubleshooting
On binary tree (C language)
[machine] [server] Taishan 200
随机推荐
2022 ape circle recruitment project (software development)
Network connection (III) functions and similarities and differences of hubs, switches and routers, routing tables and tables in switches, why do you need address translation and packet filtering?
Basic data types of MySQL
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
Jianzhi offer 04 (implemented in C language)
Talk about scalability
Rhcsa day 10 operation
Communication layer of csframework
Error C4996 ‘WSAAsyncSelect‘: Use WSAEventSelect() instead or define _ WINSOCK_ DEPRECATED_ NO_ WARN
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.
PHP programming language (1) - operators
Vs201 solution to failure to open source file HPP (or link library file)
Rhcsa12
Rhcsa - day 13
Network disk installation
Write a program to judge whether the elements contained in a vector < int> container are 9.20: exactly the same as those in a list < int> container.
Static comprehensive experiment ---hcip1
Write a program that uses pointers to set all elements of an int array to 4.18: 0.
[Galaxy Kirin V10] [server] NFS setup
Rhsca day 11 operation