当前位置:网站首页>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

  1. 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

原网站

版权声明
本文为[A little boy who studies hard]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202141415210289.html