当前位置:网站首页>SQL database: summary of knowledge points, no suspension at the end of the period
SQL database: summary of knowledge points, no suspension at the end of the period
2022-06-24 00:16:00 【Nianchi ichthyology programming】
Chapter one
1 The characteristics of database : Database data has permanent storage 、 There are three basic characteristics of organization and sharing .
2 What is? DBMS?(DBMS It's a database management system : Database management system is a system software specially used for data management and maintenance .)
3 Independence of data ( What is physical independence , What is logical independence ?)
Physical independence : It refers to when the storage location or storage structure of data changes , Does not affect the characteristics of the application .
Logical independence : When the content of information expressing the real world changes , Nor does it affect the characteristics of the application .
Chapter two
1 The three elements of the data model : That is, the basic structure of data should be included when describing data 、 Data constraints ( These two belong to the static characteristics of data ) And define operations on data ( It belongs to the dynamic characteristics of data ) Three aspects .
2 Concept layer data model : It refers to the elements with application value and their relationships in the abstract reality system ( Commonly used entities - Connection model )
Entity : It is a collection of real world objects that have common properties and can be distinguished from each other .
attribute : A data item that describes the nature or characteristics of an entity or relationship , All instances belonging to an entity have the same properties .
contact : It refers to the relationship between the internal attributes of an entity , The relation between entities usually refers to the relation between the attributes of different entities .
There are usually three types of connections between two entities :① One to one contact (1:1)② One to many connection (1:n)③ Many to many contact (m:n)
3 Organization level data model : hierarchical model 、 Mesh model 、 relational model .
4 What is the external mode ?( External mode is also called user mode or sub mode , It is a partial description of the overall data of interest to users in the real system , It is used to meet the data needs of different users of the database . A database can have multiple external schemas .)
5 What is a pattern ?( Also known as logical mode , It is a description of the logical structure and characteristics of all data in the database , Is a common data description for all users . A database has only one schema .)
6 What is the inner mode ?( Also known as storage mode . Is the underlying representation of the entire database , It describes the storage structure of data , For example, sequential storage ,B Tree storage or hashing , How indexes are organized , Whether it is encrypted, etc . There is only one inner mode .)
The third chapter
1. Candidate key : An attribute or minimum group of attributes that uniquely identifies a tuple in a relationship . There can be multiple candidate keys on a relationship .
2. Primary key : Also called primary key or primary key . Is an attribute or attribute group in a table , Used to uniquely identify a tuple . Can consist of one attribute , It can also be composed of multiple attributes .
3. Main attribute : Attributes contained in any candidate code .
4. Non primary property : Attributes not included in any candidate code .
5. What are the integrity constraints of the relational schema ?
① Entity integrity : Entity integrity is to ensure that each tuple in the relationship is identifiable and unique . It means that all tables in a relational database must have primary keys , Moreover, records without primary key value and records with the same primary key value are not allowed in the table .
② Referential integrity : Restricting the value of a column in one relationship to the value range of a column in another relationship is called referential integrity .
③ User defined integrity : Also known as domain integrity or semantic integrity . It refers to the database constraints defined for a specific application field , It reflects that the data involved in a specific application must meet the requirements of application semantics .
6. What is foreign key : set up F It's the relationship R One or a set of attributes of , If F And relationships S The main code of corresponds to , said F It's the relationship R The outer code of (Foreign Key), And call the relationship R For reference relations (Referencing Relation), Relationship S For the referenced relationship (Referenced Relation) Or purpose relationship (Target Relation). Relationship R And relationship S It doesn't have to be a different relationship .
7. What is choice σ: It selects certain tuples from the specified relationships to form a new relationship , The selected tuple satisfies the specified
The logical condition of .
8. What is projection ∏: It is to select the vertical direction of the specified relationship , And form a new relationship . It involves two processes :1) Select the specified attribute 2) Delete duplicate lines , Form a new relationship
9. What is connection : Used to connect two related relationships , To create a new relationship .
10. What are the connection requirements : There are two commonly used connections : Equivalent connection and natural connection .
Natural connection is a special kind of connection , It requires two relations are compared must be the same component attribute group , And remove duplicate attribute columns from the results .
The difference between natural connection and equivalent connection is :
Natural join requires equal components to have a common attribute name , Equivalent connection does not require ;
Natural join requires that duplicate attribute names be removed , Equivalent connections don't do that .
11. Basic relational algebra should be able to write .
Eg: Check and repair c02 Student number and grades of the students of course No .
∏sno, grade(σcno=‘c02’(SC))
Inquiry information department c04 Names and grades of students in course No .
∏sname, grade(σcno=‘c04’(SC)σsdept=‘ Information Department ’(Student))
The inquiry has been revised to 2 The name of the student in the semester course 、 Department and selected course number .
∏sname, sdept,cno(σsemester=2(Course) SC Student)
Query the student number and name of students who have taken all courses .
∏sno, sname(Student (SC ÷ ∏cno(Course)))
The query selected “VB” Course and test score is greater than or equal to 80 Student name of 、 Department and grades .
∏Sname, Sdept, Grade(σCname=‘VB’∧ Grade>=80(CourseSCStudent))
or :
∏Sname, Sdept, Grade(σCname=‘VB’(Course)σGrade>=80(SC)Student)
Among all the students , The query did not select “ Computer culture ” The name of the student and his / her department .
∏Sname, Sdept(Student)- ∏Sname, Sdept(σCname=‘ Computer culture ’ (CourseSC
Student) )
or :
∏Sname, Sdept(Student)- ∏Sname, Sdept(σCname=‘ Computer culture ’
(Course)SCStudent)
The fifth chapter
1.SQL It can be divided into four parts according to its functions : Data definition function 、 Data control function 、 Data query function 、 Data manipulation function .
2. Define the base table : Use SQL In language CREATE TABLE Statements for , Its general format is :
CREATE TABLE < Table name > (< Name > < data type > [ Column level integrity constraint definition ]{,< Name > < data type > [ Column level integrity constraint definition ] … }[, Table level integrity constraint definition ] )
Eg:
example . by Student Table to add “ major ” Column , This column is defined as :Spec char(10), Allow space .
ALTER TABLE Student
ADD Spec char(8) NULL
example . Add a new “ major ” The type of the column is changed to char(20).
ALTER TABLE Student
ALTER COLUMN Spec char(20)
example . Delete the newly added “ major ” Column .
ALTER TABLE Student
DROP COLUMN Spec
3. constraint :
NOT NULL: The limit column value is not empty .
DEFAULT: The default value for a given column .
UNIQUE: Limit column values are not repeated .
CHECK: Limit the value range of the column .
PRIMARY KEY: Specify this column as the primary code .
FOREIGN KEY: Define this column as a foreign code that references other tables .
4. Delete relation table :DROP TABLE < Table name >
5. Modify the relation table :
ALTER TABLE < Table name >
[ ALTER COLUMN < Name > < New data types >] -- Change column definition
[ADD < Name > < data type > < constraint >] -- Add new column
[DROP COLUMN < Name >] -- Delete column
[ADD [constraint < Constraint name >] Constraint definition ]– Adding constraints
[DROP [constraint] < Constraint name >] -- Delete constraints
6. Data integrity : Data integrity refers to the correctness and consistency of data . Data integrity constraints are designed to prevent the existence of data that does not conform to semantics in the database . These semantic constraints imposed on data are data integrity constraints .
7. Object of integrity constraint : Column level constraints 、 Tuple constraint 、 Relational constraints
Column level constraints : For data types 、 data format 、 Value range or value set 、 NULL constraint .
Tuple constraint : Is a constraint on the relationship between fields in a tuple .
Relational constraints : Between several tuples 、 Constraints on the connections between relationships .
8.PRIMARY KEY constraint
example : Add master code constraints to the employee table and the worksheet respectively .
ALTER TABLE Employee list
ADD CONSTRAINT PK_EMP PRIMARY KEY ( Employee number )
ALTER TABLE Worksheet
ADD CONSTRAINT PK_JOB PRIMARY KEY ( Job number )
9.UNIQUE constraint
example . For employees “ Phone number ” Column add UNIQUE constraint .
ALTER TABLE Employee list
ADD CONSTRAINT UK_SID UNIQUE ( Phone number )
10.FOREIGN constraint
example . Add a foreign code reference constraint to the job number of the employee table , This column refers to the job number column of the worksheet .
ALTER TABLE Employee
ADD CONSTRAINT FK_job_id FOREIGN KEY ( Job number ) REFERENCES Worksheet ( Job number )
11.DEFAULT constraint
example . The default value for defining the salary of the employee table is 1000.
ALTER TABLE Employee
ADD CONSTRAINT DF_SALARY DEFAULT 1000 FOR Wages
12.CHECK constraint
example 1. In the employee table , The salary of a restricted employee must be greater than or equal to 1000 Constraints .
ALTER TABLE Employee
ADD CONSTRAINT CHK_Salary CHECK ( Wages >= 1000 )
example 2. Add a constraint that restricts the minimum wage of the payroll to be less than or equal to the maximum wage .
ALTER TABLE Work
ADD CONSTRAINT CHK_Job_Salary CHECK ( minimum wage <= Maximum wage )
Chapter six
1. Must master sub query 、 grouping ( Including aggregate functions )、 Table connections 、 Additions and deletions 、DELETE、UPDATE、 String matching query
① Subquery
② Inquire about
③ Insert
④ Update data
⑤ Delete
⑥ grouping + Aggregate functions +HAVING Clause
⑦ Table connections
⑧ String matching query
2. The difference between inner connection and outer connection :( The internal connection of two tables must meet the conditions , Connect a table externally to meet the requirement of reallocation )
Internal connection : Inner connection is one of the most commonly used connection types . When using internal connections , If the related fields of two tables meet the connection conditions , Then extract the data from the two tables and combine them into a new record . Be careful : Connection fields in connection conditions must be comparable , That is, it must be a column with the same semantics , Otherwise, the comparison will be meaningless .
External connection : Only the data in one table must meet the connection conditions , The data in another table may not meet the connection conditions .
Chapter vii.
1. Clustered index : Physical sorting of data by index key .
2. Nonclustered indexes : Do not physically sort data .
3. Create and delete indexes
① Create index
② Delete index
4. Definition of view : It is a logical window composed of data selected from the basic table of the database , Is a combination of partial row and column data of a basic table . A view is a virtual table .
Chapter viii.
1. Nontrivial functional dependencies : If X→Y, but Y Not included in X, said X→Y It's a nontrivial functional dependency .
2. Trivial function depends on : If X→Y, but Y Included in X, said X→Y It's trivial functional dependencies .
3. Completely function dependent : If X→Y, And for the X An arbitrary proper subset of X‘ There are X‘—/→Y, said Y The complete function depends on X, Write it down as :.
4. Part of the function depends on : If X‘→Y establish , said Y Some functions depend on X, Write it down as :.
5. The transfer function depends on : If X→Y( Nontrivial function dependency , also Y—/→X)、Y→Z, said Z The transfer function depends on X .
6. Problems arising from functional dependencies : Data redundancy problem 、 Data update problem 、 Data insertion problem 、 Data deletion problem
7. Relationship normalization : There will be “ Bad ” The theory of transforming functional dependency patterns into good relational patterns .
8. First normal form : Relationships that do not contain duplicate groups .
9. Second normal form : If R(U,F)∈1NF, also R Each non primary attribute in the is completely functionally dependent on the primary code , be R(U,F)∈2NF.
10. Third normal form : If R(U,F)∈2NF, And all non - primary attributes do not depend on the primary code , be R(U,F)∈3NF.
11.BC normal form (BCNF): Relationship model R∈1NF. If a function depends on a set F All functional dependencies in X→Y(Y Not included in X) The left part of the contains R Any candidate key for , be R∈BCNF. In other words ,BCNF The left part of all dependencies in the must contain candidate keys .
Eg: example 1、 Take the warehouse management relation table as an example : Warehouse ID, Store things ID, Administrators ID, Number . An administrator works in only one warehouse , A warehouse can store many items .
Semantic analysis :
( Warehouse ID, Store things ID)→( Administrators ID, Number )
( Administrators ID, Store things ID)→( Warehouse ID, Number )
In line with the third paradigm .
( Warehouse ID)→( Administrators ID) ( Administrators ID)→( Warehouse ID), It does not conform to BCNF normal form .
decomposition method : Decompose the warehouse management relation table into two relation tables : Warehouse management :StorehouseManage( Warehouse ID, Administrators ID); Warehouse :Storehouse( Warehouse ID, Store things ID, Number ).
example 2、 There's a relationship model :Student( Student number , full name , Tutor No , Tutor name , Course no. , Course description , achievement )
semantics : A student has only one tutor , Students can choose multiple courses .
Normalize it into 3NF Of .
1. This watch is 1NF, Its functional dependency is :
Student number → full name , Student number → Tutor No , Student number → Tutor name , Course no. → Course description ,
( Student number , Course no. )→ achievement
The main code is ( Student number , Course no. )
There are some functional dependencies , No 2NF, First, it is decomposed into 2NF.
Student ( Student number , full name , Tutor No , Tutor name ),
Course ( Course no. , Course description ),
achievement ( Student number , Course no. , achievement ) Are all 2NF
2. Judge whether it is 3NF
“ Student ” Table is not 3NF, Its functional dependency is :
Student number → full name , Student number → Tutor No , Tutor No → Tutor name ,
∴ Student ID transfer → Tutor name
Eliminate attributes that depend on the decision maker , Put them in a separate table , obtain :
Student ( Student number , full name , Tutor No ), mentor ( Tutor No , Tutor name )
12. There are two decomposition criteria for relational schema : Schema decomposition has lossless connectivity ; Schema decomposition preserves functional dependencies .
What is lossless connection means that the decomposed relationship can be restored to the original relationship through natural connection , That is, the relationship obtained through natural connection is compared with the original relationship , No more information 、 Without losing information .
What is preserving functional dependency decomposition means in the process of schema decomposition , Features that cannot be lost in functional dependencies , That is, schema decomposition cannot destroy the original semantics .
additional p154 After class exercises 6、7、8.
Chapter nine
1. Concept of transactions : A transaction is a user-defined series of data operations , These operations are performed as a complete unit of work . All statements in a transaction as a whole , Or all , Or none at all .
2. The transaction ACID features : Atomicity (A): Is the logical working unit of the database , Operations in transactions , Or do it all , Either not .
Uniformity (C): The result of transaction execution must be to change the database from one consistency state to another .
Isolation, (I): The execution of one transaction in the index database cannot be disturbed by other transactions .
persistence (D): Once the matter is submitted , The change to the data in the database is permanent , Future operations or failures will not have any impact on the operation results of the transaction .
3. What is concurrency control : It is necessary to use the correct method to schedule concurrent operations , Make the execution of one transaction free from the interference of other transactions , Avoid data inconsistencies .
4. Problems caused by concurrent operations : Lost data modification 、 read “ dirty ” data 、 It can't be read repeatedly 、 produce “ ghost ” data .
5.S lock ( Shared lock ): You can read but not modify transaction data . You can continue to add S lock , But we can't add X lock , Until released S Lock it .
6.X lock ( Exclusive lock ): Allows you to read and modify transaction data . There are exclusive locks , No locks , Until released X Lock it .
7. Blocking agreement :
First level blockade protocol : On business T Add... To the data to be modified X( Exclusive lock ) lock , Until the end of the transaction ( Including normal end and abnormal end ) Release only when . The first level blocking protocol can prevent data loss and modification , And make sure that things T It's recoverable . There is no guarantee of readability and non readability “ dirty ” data .
Secondary blockade protocol : First level blocking protocol plus transactions T Add... To the data to be read S( Shared lock ) lock , Release after reading S lock . It can prevent data loss and modification , It also prevents reading “ dirty ” data . There is no guarantee that data can be read repeatedly .
Three level blockade agreement : First level blocking protocol plus transactions T Add... To the data to be read S lock , And do not release until the transaction ends . It can prevent data loss, modification and unread “ dirty ” data , It also prevents non repeatable reading .
8. Deadlock : Two transactions wait for each other to release resources , It will cause deadlock .
9. The way to solve the deadlock problem : One is to take certain measures to prevent deadlock ; The other is to allow deadlock , But use certain means to regularly diagnose whether there is deadlock in the system , If there is one, it shall be cancelled .
10. Deadlock is not allowed : Deadlock prevention :(1) One time blockade ( Each transaction locks all data to be used at once , Otherwise, we can't carry on )(2) Sequential blockade ( Set a blocking order for data objects in advance , All transactions are blocked in this order ) It's hard to achieve .
11. Allow deadlock : Diagnosis and removal of deadlock :(1) Overtime method ( The waiting time has exceeded the specified time limit , A deadlock occurs . Easy to implement , However, it is prone to misjudgment and unable to handle the deadlock in time )(2) Waiting graph
Chapter ten
1. The structural design includes : Conceptual structural design 、 Logical structure design and physical structure design .
2. Design the whole picture E-R The conflicts caused by the model are : Property conflict 、 name conflict 、 Structural conflict .
3. How to transform conceptual model to relational model :
additional p186 After-school exercises 10、11
( The last big question : Draw by yourself according to the meaning E-R chart , Convert to conform to 3NF Of , Find the primary and foreign keys )
边栏推荐
- Comment utiliser l'entrepôt de données pour créer une table de synchronisation
- I was cheated by my colleagues to work overtime on weekends. I haven't seen redis used like this...
- Android 3年外包工面试笔记,有机会还是要去大厂学习提升,android开发实习面试题
- 毕业设计-论文写作笔记【毕设题目类型、论文写作细节、毕设资料】
- 【第25天】给定一个长度为 n 的数组,统计每个数出现的次数 | 计数哈希
- 跟着CTF-wiki学pwn——ret2text
- 如何利用數倉創建時序錶
- Android 3年外包工面试笔记,有机会还是要去大厂学习提升,作为一个Android程序员
- 抖音实战~密码找回
- Drag and drop report design - new features of jimureport 1.4.0
猜你喜欢

SAVE: 软件分析验证和测试平台

Chaos engineering, learn about it

Android AIDL:跨进程调用Service (AIDL Service),kotlininvoke函数

EasyCVR程序以服务启动异常,进程启动却正常,是什么原因?

The easycvr program started abnormally as a service, but the process started normally. What is the reason?

Android 3年外包工面试笔记,有机会还是要去大厂学习提升,作为一个Android程序员

利用Scanorama高效整合异质单细胞转录组

Tiktok practice ~ one click registration and login process of mobile phone number and password (restrict mobile terminal login)

Test - use case - detail frenzy

extern、struct等关键字
随机推荐
迷茫的测试/开发程序员,不同人有着不同的故事、有着不同的迷茫......
Android 7,2021最新Android面试笔试题目分享
Salesforce batch apex batch processing (V) asyncapexjob intelligence
SQL数据库:知识点汇总,期末不挂科
逻辑的定义
What is the future development of palmprint recognition technology?
extern、struct等关键字
利用Scanorama高效整合异质单细胞转录组
[technical grass planting] Tencent Yunhao wool (consumption) record on the double 11
Throttling and anti shake
Dart series: using generators in dart
SAVE: 软件分析验证和测试平台
Batch renaming of images by MATLAB
产业互联网时代将依靠源自于产业本身的产品、技术和模式来实现的
C语言:关于矩阵右移问题
解决base64压缩文件,经过post请求解压出来是空格的问题
Interview notes for Android outsourcing workers for 3 years. You still need to go to a large factory to learn and improve when you have the opportunity. Interview questions for Android Development Int
I was cheated by my colleagues to work overtime on weekends. I haven't seen redis used like this...
What is medical treatment? AI medical concept analysis AI
Interpreting the "four thoughts" of Wal Mart China President on the transformation and upgrading of physical retail