Basic knowledge about database

10ecaec08a354a218438efcc9f9119b5.jpgChapter 1 Concept

 

 

1. Data: Symbolic records describing things are called data. Characteristics: Data and interpretation about the data are inseparable.

 

2. Database: A collection of large amounts of data that is stored in a computer for a long time, is organized, and can be shared. The data in the database is organized, described and stored according to a certain data model. It has small redundancy, high data independence and easy scalability, and can be shared by various users. Features: permanent storage, organized, shareable.

 

3. Database management system (DBMS): a layer of data management software located between the user and the operating system. Main functions: data definition function (DDL); data organization, storage and management; data manipulation function (DML); database transaction management and operation management; database establishment and maintenance functions; other functions.

 

4. Database system (DBS): consists of database, database management system (and its development tools), application system, and database administrator.

 

5. Three stages of data management technology: manual management, file system, and database system.

 

6. Two types of data models: conceptual model (also called information model); logical model and physical model

 

7. The components of the data model: data structure, data manipulation and data integrity constraints.

 

8. Conceptual model: used for modeling the information world. It is the first level of abstraction from the real world to the information world. It is a powerful tool for database designers to carry out database design and is also the language for communication between database designers and users.

 

9. Concepts in the information world: entities, attributes, codes, domains, entity types, entity sets, and relationships; the relationship between two entities is divided into one-to-one, one-to-many, and many-to-many.

 

10. ER diagram: A method of representing entity types, attributes and relationships. Entity types use rectangles, attributes use ellipses, and relationships use diamonds.

 

11. The integrity constraints of relationships include three categories: entity integrity, referential integrity, and user-defined integrity.

 

12. The three-level schema structure of the database system: schema, external schema, and internal schema. Secondary image of the database: external schema/schema image, schema/internal schema image.

 

Chapter 2 Relational Database

 

1. The relational model consists of three parts: relational data structure, relational operation set and relational integrity constraints.

 

2. Relational operations: query operations and insertion, deletion, and modification operations. Query operations can be divided into selection, projection, connection, division, union, difference, intersection, Cartesian product, etc.

 

3. Entity integrity: the main attribute cannot be empty; referential integrity: references between relationships (usually two tables, or one table also exists inside); user-defined integrity.

 

Chapter 3 Relational Database Standard Language SQL

 

1. SQL: Structured Query Language.

 

2. The outer schema corresponds to views and partial tables, the schema corresponds to basic tables, and the inner schema corresponds to storage files.

 

3. Basic table: A table that exists independently. In SQL, a relationship corresponds to a basic table, and one or more basic tables correspond to a storage file. A table can have several indexes, and the indexes are also stored in the storage file.

 

4. View: A table derived from one or several basic tables does not exist in the database itself. That is, the database only stores the definition of the view and does not store the data corresponding to the view. The view is a virtual table and can be defined on the view. view.

 

5. Storage file: Its logical structure constitutes the internal schema of the relational database, and its physical structure is arbitrary and transparent to users.

 

6. SQL query

 

Common queries

SHOW DATABASES; Query all databases

use database name; use a database

SHOW TABLES queries all tables

SHOW COLUMNS FROM table name to query all columns of the table

SELECT column FROM table name query

SELECT column 1, column 2... FROM table name multi-column query

SELECT * FROM table name all query (query all columns)

7. Database service environment installation and deployment

Deploy database in windows system: mysql

https://dev.mysql.com/downloads/installer/

PHPstudy package---contains database service---start it

Method 1: Connect to the database (command line operation management)

Connect to the database service: cmd ---> Switch to the PHPstudy database program directory ---> Connect to the database

mysql.exe -uroot -proot

 

Method 2: Connect to the database (graphical interface operation)

Install the database connection program software: Navicat installation and deployment

To achieve remote connection to the database:

Establish a connection locally: localhost == 127.0.0.1

 

Deploy database in Linux system: mysql

https://dev.mysql.com/downloads/mysql/

 

Prepare the Linux environment: vmware virtual software --- load virtual host --- start

Deploy database service: mariadb --- yum install -y mariadb (operation database command) mariadb-server

Start the database service: systemctl start mariadb

 

Method 1: Connect to the database (command line)

Virtual host environment --- mysql -uroot

 

Method 2: Connect to the database (graphical interface)

??? How to establish a connection with the virtual host data path service

 

05. Database operation and management knowledge

1) Operate database-related SQL commands

· Create database information:

Statement format: CREATE DATABASE database name;

Operation command: CREATE DATABASE PHP;

· View database information:

Statement format: show databases;

· Select specified database information:

Statement format: use database name;

Operation command: use php;

· View table information in the library:

Statement format: show tables;

· Delete specified database information:

Statement format: drop database database name;

Operation command: drop database php;

 

2) SQL commands related to operating data tables

· Create table information:

Statement format: CREATE TABLE table name (field name 1 field type, field name 2 .... field name n field type n);

Operation command:

create table xueyuan(

name varchar(15),

sex char(5),

age int(5),

xueli char(10),

jingyan bool,

xinzi float(10,2)

);

 

· View field information in the table:

Statement format: desc table name

Operation command: desc xueyuan;

+---------+-------------+------+-----+---------+-------+

| Field | Type | Null | Key | Default | Extra |

+---------+-------------+------+-----+---------+-------+

| name | varchar(15) | YES | | NULL | |

| sex | char(5) | YES | | NULL | |

| age | int(5) | YES | | NULL | |

| xueli | char(10) | YES | | NULL | |

| jingyan | tinyint(1) | YES | | NULL | |

| xinzi | float(10,2) | YES | | NULL | |

+---------+-------------+------+-----+---------+-------+

6 rows in set (0.00 sec)

 

· View table information creation method:

Statement format: SHOW CREATE TABLE table name;

Operation command: SHOW CREATE TABLE xueyuan\G;

*************************** 1. row **************************

Table: xueyuan

Create Table: CREATE TABLE `xueyuan` (

`name` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL,

`sex` char(5) COLLATE utf8_unicode_ci DEFAULT NULL,

`age` int(5) DEFAULT NULL,

`xueli` char(10) COLLATE utf8_unicode_ci DEFAULT NULL,

`jingyan` tinyint(1) DEFAULT NULL,

`xinzi` float(10,2) DEFAULT NULL

) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci

 

· Delete table information:

Statement format: drop table name name;

Operation command: drop table oldboy;

 

· Create table to set engine information and default character encoding information:

mysql> create table test(

name varchar(15),

sex char(5),

age int(5),

xueli char(10),

jingyan bool,

xinzi float(10,2)

)ENGINE=InnoDB DEFAULT CHARSET=utf8;

 

3) SQL commands related to operating data fields

· Modify field data type information

Statement format: alter table table name modify field name modified data type;

Operation command: alter table test modify sex varchar(10);

 

· Add field information in the table:

Statement format: alter table table name add column field name field type;

Operation command: alter table test add column oldboy date;

 

· Add field information in the table: You can specify the location where the control field is added

Statement format: alter table table name add field name bool after which field to add after;

Operation instructions: alter table test add oldgirl bool after age;

 

Add field information in the table: insert the specified field into the first column

Statement format: alter table table name add field type first;

Operation instructions: alter table test add oldbaby char first;

 

· Delete field information in the table:

Statement format: alter table table name drop column field name;

Operation instructions: alter table test drop column oldbaby;

 

· Modify field name information:

Statement format: alter table table name change original field name modified field name field type;

Operation command: alter table test change xueli edu varchar(15);

 

· Modify the order of existing fields:

Statement format:

alter table table name modify field name type first; --- directly move the specified field to the first column

alter table test modify field name type after field name; --- Move the field to after the specified column

 

· Modify the name of the table in the database:

Statement format: alter table old table name rename new table name;

Operation command: alter table test rename new_test;

 

4) Introduction to database field data types/character encoding

Refer to the mysql documentation introduction

 

5) Database index operation

Introduction to the concept of index: It can improve the efficiency of searching for specified data

Introduction to index classification: ordinary index, unique index (field information cannot be repeated), primary key index (field information cannot be empty)

 

Index creation method:

Normal index creation: MUL

Syntax format: alter table table add index (field);

Operation command: alter table xueyuan add index(name);

 

Unique index creation: UNI

Syntax format: alter table table add UNIQUE (field)

Operation command: alter table xueyuan add UNIQUE(xueli);

 

Primary key index creation: PRI

Syntax format: alter table table add PRIMARY KEY (field)

Operation command: alter table xueyuan add primary key(jingyan);

 

How to delete index information???

Syntax format: drop index index name on table name

Syntax command: drop index jingyan ON 

Guess you like

Origin blog.csdn.net/weixin_57763462/article/details/132782838