I. Introduction of the Database
(1) database is the repository of data, data is not directly placed in the database, the database is placed in a table, the table is the data stored;
(2) History of the database
Embryonic stage-File system: Use disk files to store data;
Primary stage-The first generation of databases: A network model, a hierarchical model of the database;
Intermediate stage-second generation of database: relational database and structured Query language;
Advanced stage--New generation database: "Relational-Object" type database;
(3) Hierarchical model: Hierarchical data Model simulates various hierarchical organizations in real life, and the resource manager can be considered to be organized according to the hierarchical model;
Advantages: Classification Management, if the query of the same class of data is very convenient;
Cons: If you query a lot of data that is not the same class, the efficiency is very low;
(4) relational model; the relationship between records and records is linked through the relationships between the attributes to ensure the independence of data and to form the relationship between data sets;
In the relational model, each table is independent, and the relationship is established through public fields;
Relationship: Public fields of two tables are called relationships;
Advantages: The table is independent, what data needs to be queried in which table;
Disadvantages: Multi-table query, inefficient;
II. Introduction to SQL statements
(1) Structured query Language structured querying language, which is used to manipulate relational database;
(2) commonly used relational database: Access, MySQL, SQL Server, Oracle;
Standard SQL is the operation statement supported by all relational databases, and standard SQL is called SQL-92, but each database expands its own things on the basis of standard SQL.
SQL Server Extension SQL statement: T-SQL;
Oracle Extended SQL statement: PL/n;
MySQL extended SQL statement: MySQL;
Third, connect the database
(1) After installing the database, MySQL comes with a MySQL command line client, this client is very convenient, but can only connect to local MySQL;
Connect to the server through the Windows command line;
(2) DOS command:
Access to other disks: disk name:;
Enter a folder under the drive letter: CD path;
Go to the parent directory of the current path: CD. / ;
Go to root directory: CD/;
Four, database operations
Database essence is a file, through MySQL can create and manage multiple databases;
(1) Create a database:
Syntax: CREATE database name;
If you create a database that already exists, you will get an error, and when you create it, create it if it doesn't exist.
Syntax: Create DB if not exists database name;
If you create a database name that is a keyword, you will get an error, and you can resolve the problem by adding anti-quotes to the name;
When creating a database, specify the character encoding of the database, syntax: CREATE database name Charset=utf8;
(2) Query the database:
Syntax: show database name;
(3) Change the database:
Change the character encoding of the database, syntax: ALTER DATABASE name Charset=utf8;
(4) Delete the database:
Syntax: drop database name;
When the database is deleted, determine whether the database exists, if it exists before deleting;
Syntax: DROP database name if exists;
(5) Select database:
Syntax: use database name;
(6) Show all databases:
Syntax: show databases;
(7) Display the creation statement for the database:
Syntax: show create database name;
V. The concept of a table
(1) line is also called record, one line is a record;
(2) A column is also called a field, a column is a field, the field is also called a property;
(3) A table contains multiple fields;
(4) Creating table, Syntax: CREATE TABLE data table name (field 1 data type);
Primary Key Features: cannot be repeated, cannot be empty, a table can have only one primary key, the primary key can be composed of several fields together;
Data types: int, decimal (total number of digits, decimal place), char () fixed length, varchar () variable length, text large paragraph literal,
Vi. Creating a Table
(1) View all tables
Syntax: show tables;
(2) View CREATE TABLE SQL statement
Syntax: Show create table data table name;
(3) Display table structure
Syntax: describe data table name;
(4) Delete a table
Syntax: DROP table 1, table 2, table 3;
(5) Creating a complex table
Grammar:
Vii. Data manipulation
(1) Inserting data
Syntax: Inset into table name (field name 1, field name 2) VALUES (value 1, value 2);
The Insert field can be inconsistent with the order of the fields in the database, but the order of the values and inserted fields must be consistent;
The inserted field can be omitted, and the inserted value is consistent with the order and number of fields in the data table;
Syntax: Inset into table name values (value 1, value 2, value 3 ...);
autogrow insert: Inset into table name values (null, value 2, value 3 ...);
Insert Default value: INSERT into table name values (null, value 2, value 3, default ...);
(2) Modify the data
Syntax: Update table name set field 1= value 1, field 2= value 2 where condition;
(3) Delete data
Syntax: delete from table name [where condition];
(4) Query data
Syntax: SELECT * FROM table name;
Syntax: Select column name from table name [WHERE Condition] [order by sort] [limit restriction];
(5) operator
The above introduces the introduction of PHP Learning-database learning, including aspects of the content, I hope to be interested in PHP tutorial friends helpful.