Database basis of understanding learning -Mysql

  1. Profile
      database, modern data storage means storage, is a special file, which stores the data needed.

Features:

Persistent storage
read and write speed high
to ensure the validity of data
for program support is very good, easy to expand

  1. MySQL
    (. 1) having a data integrity:

  A database is a complete service units, may comprise a plurality of tables, data is stored in a table. In the table in order to store data more accurate, to ensure correct and effective data, when creating the table, add some mandatory verification for the table, including the type of data fields, constraints.

Constraint Description:

Primary Key primary key: sequentially stored physically;
nonempty not null: This field is not allowed to fill nulls;
only unique: the value of this field must be unique;
default default: When this value does not fill the default value, if the fill when to fill prevail;
foreign key foreign key: to constrain the relationship field, when the field is filled relationship value, the associated table will query this value exists, if there is then complete success, if it does not exist and failed to fill in throws an exception;
Note: Although the foreign key constraint can guarantee the validity of the data, but the crud carrying data (add, modify, delete, query) when, will reduce the performance of the database, it is not recommended, then the validity of the data how to ensure it? A: it can be controlled at the logical level.
(2) Mysql- relational database, the core elements:

Data row (record)
data columns (fields)
the data table (set of data lines)
database (a collection of data tables)
(3) characteristics:

Written in C and C ++, and uses a variety of compilers tested to ensure source code portability;
support multiple operating systems, such as Linux, Windows, AIX, FreeBSD, HP-UX, MacOS, NovellNetware, OpenBSD, OS / 2 Wrap, Solaris etc;
offer a variety of programming languages the API, such as C, C ++, Python, Java , Perl, PHP, Eiffel, Ruby etc;
support multi-threaded, full use of CPU resources;
optimized SQL query algorithm, effective improve query speed;
multi-language support, common coding such as GB2312, BIG5, UTF8;
provide TCP / IP, ODBC and JDBC database connectivity and other ways;
to provide for management, inspection and management tools to optimize database operations;
large database. Can handle tens of millions of records have large databases;
support for multiple storage engines;
MySQL software uses a dual licensing policy, which is divided into community and commercial versions, due to their small size, high speed, low cost of ownership, especially this feature of open source, development of small and medium websites have chosen MySQL as the site database;
MySQL data using standard SQL language form;
Mysql can be customized using the GPL agreement, you can modify the source code to develop their own Mysql system;
online DDL change function;
copy a global transaction identifier;
copy no collapse slave;
copying from the multithread machine.
3. Basic Operation - CRUD
(1) sql statement is divided into:

DQL: data query language for data query, such as select

DML: Data Manipulation Language, the data add, modify, delete, such as insert, udpate, delete

TPL: transaction processing language, transaction processing, including the begin transaction, commit, rollback

DCL: Data Control Language, authorization and permissions recovery, such as grant, revoke

DDL: data definition language, a database, a management table or the like, such as create, drop

CCL: pointer control language, by controlling the operation of the pointer table is completed, as declare cursor

(2) CRUD

① inquiry

Discover all columns
select * from table name;

例:select * from classes;

The query specifies column
can be used as an alias for a column or table, select the column 1, column 2, ... from table name;

例:select id,name from classes;

② increase

格式:INSERT [INTO] tb_name [(col_name,...)] {VALUES | VALUE} ({expr | DEFAULT},...),(...),...

Full row insertion: the sequence table sequentially value field corresponds
insert into table values (...)

Example: insert into students values ​​(0, 'Can Li', 1 'Xi', '2019-1-6');

Insert part of the column: the column order corresponding to the order value given
insert into table (column 1, ...) values (values 1, ...)

Example: insert into students (name, hometown, birthday) values ​​( 'WANG Si', 'Sichuan', '2019-3-2');

The above statement can insert a row into the table, multiple rows of data may be inserted only once, which can reduce the communication with the database

Full insert columns in multiple rows: column order and sequence analysis values corresponds
insert into table values (...), (...) ...;

例:insert into classes values(0,'day1'),(0,'day2');

insert into table (column 1, ...) values ​​(values ​​1, ...), (values ​​1, ...) ...;

Example: insert into students (name) values ​​( 'Li Si'), ( 'Di'), ( 'width Deng')

③ Modify

Format: the UPDATE tbName the SET exprl col1 = {| the DEFAULT} [, {col2 = expr2 | default}] ... [WHERE condition judgment]

update table values ​​1 SET = 1, column 2 value = 2 ... WHERE conditions are

例:update students set gender=0,hometown='西安' where id=5;

④ Delete

DELETE FROM tbname [where conditional]

delete from table where conditions

例:delete from students where id=5;

Tombstone, is a change in the nature of the operation

update students set isdelete=1 where id=1;

Guess you like

Origin blog.51cto.com/14551318/2440399