Database Systems Learning (II)

A relational database

1. What is the relationship database?

Data model uses the relational model database is a relational database.

2. The structure of a relational database?

A set of relational database tables, each table name unique. Each table has rows and columns, a row can represent the link between a set of values. Relationship concept conceptual and mathematical tables are closely related.

Tuples (tuple): a group worthy of sequence. (N-tuple that has n-tuple values)

The term relational model: used to refer to the representative relationship, means acting tuple attribute refers to the column.

Relationship instance: represents a particular instance of a relationship.

It may be in the range of the relationship between each attribute: domain.

A null value: that value is unknown or absent. Null give database access and update brings a lot of difficulties, it should avoid the use of null values.

3. database schema

The database schema is the logical design of the database, the database instance is an instance of the database data.

Relational databases are based on relational database model.

Code: used to distinguish the different tuples.

Ultra Code: one or more sets of attributes, which can set a unique identifier for each tuple.

Minimum Super Size (candidate key): any subset can not become Super Size Super Size is a candidate code.

Master code: Representative database designer selected, the main candidate code used to distinguish the different tuples in a relation.

Code is a relationship between the nature of the whole, rather than the properties of the individual tuple. It specifies the code represents the constraint of things to be modeled in the real world.

Primary key value of the choice should be rarely or never change properties.

Outer code: a relational schema (r1) further comprises a relational schema (r2) of the master key, the attribute of the outer code in the r2 r1. also referred to as a reference relationship r1 outer code dependent. r2 relationship is called outer code reference.

Referential integrity constraints: relation to any reference value tuples on specific attributes necessarily equal to the reference value tuples in a relation on a specific attribute,

4. FIG Mode

The database schema is a diagram showing a schematic diagram graphically.

5. relational query language

Divided into procedural and non-procedural languages.

Procedural language: such as relational algebra.

Relational algebra relationship with one or two inputs, produce as a result a new relationship.

Non-procedural: The relational calculus.

Relational calculus defined using predicates desired result, without giving a specific procedure to obtain the results.

6. Relational Operators

Single relationship: (1) selecting a specified predicate conditions meet tuple (2) selected from a specific property relationships.

The relationship between the two: the natural connection, Cartesian product, and, within the connector, the external connector.

Relational algebra: selection, projection, natural join, Cartesian product, and

Two, SQL

SQL is the most widely used database query language.

1. Composition: (1) Data Definition Language: (2) Data Manipulation Language: (4) the view definition (3) Integrity (5) Transaction Control (6) embedded SQL and dynamic SQL (. 7) authorization

2. sql data definition

(1) Basic Type

char(n)/varcahr(n)/int/smallint/numeric(p,d)/real,double precision/float(n)

(2) basic modes defined

create table....

Integrity constraints: primary key, foreign key constraints, a non-null constraints

The basic structure (3) SQL query

  • Single relational query
  • Multi-relational query
  • Natural connection
  • External connections

3. Additional basic operations

(1) computing renamed

(2) String Operations

String Functions, like operators, defined escape character escape, not like, similar to (matching stronger than like)

(4) Property Description Query  

* Matches all properties

(5) Sort

order by desc/asc

(6) where clause predicate

between ... and ...    (a,b,c)

4. The set operation

I set union and set intersect except complement

(1) union of two combined result set, return a new set of results

union would result set to be re-union all does not go heavy

(2) intersect intersection operations

Similarly, intersect all go heavy

(3) except the difference calculation

Above, except all go heavy

5. a null value

Comparison operation involving null values, the result is unknow

  • and: true and unknow result is unknow, false and know the result is false, unknow and unknow result is unknow
  • or: true or unknow result is true, false or unknow result is unknow, unknow or unknow result is unknow
  • not: not unknow result is unknow

6. Aggregate Functions

Literally means to gather more items put together. That is, to a collection or multiple collections as input and returns a single worthwhile function

  • The average avg
  • Minimum min
  • The maximum value max
  • The total sum
  • Total count

(1) Basic gather

(2) aggregation packet

(3) having clause

(4) gather for null values ​​and boolean values

In addition to all of the aggregate functions null values ​​are ignored (*) other than count

SQL: 1999 introduced Boolean data type, there are true, false, unknow three values. There are two aggregate functions some, every

(5) nested subqueries

from, back where nested subqueries

(6) set membership 

in

(7) a set of comparison

some,all

(8) empty relationship test

exists

(9) Existence of repeated testing tuple

unique

(10) with clause

It is used to define temporary relations

(11) a scalar subquery

7. database modifications

(1) Delete

delete from where

(2) Insert

insert into values

(3) update

update set where

 

Guess you like

Origin www.cnblogs.com/feifei123/p/11748263.html