MySQL study notes 02 [SQL basic concepts and general grammar, database CRUD operations]

  • MySQL Document-Dark Horse Programmer (Tencent Weiyun): https://share.weiyun.com/RaCdIwas
  • 1-MySQL foundation.pdf, 2-MySQL constraints and design.pdf, 3-MySQL multi-table query and transaction operation.pdf
  1. MySQL study notes 01 [database concept, MySQL installation and use] [day01]
  2. MySQL study notes 02 [SQL basic concepts and general grammar, database CRUD operations] [day01]
  3. MySQL study notes 03 [CRUD operations of database tables, basic operations recorded in database tables, client-side graphical interface tool SQLyog] [day01]

  4. MySQL study notes 04 [database query operations, table constraints] [day01, day02]

  5. MySQL study notes 05 [multi-table operation, three paradigms, database backup and restore] [day02]

  6. MySQL study notes 06 [multi-table query, sub-query, multi-table query exercises] [day03]

  7. MySQL study notes 07 [transaction, user management and authority management] [day03]

table of Contents

03 SQL basic concepts and general syntax

SQL general syntax (semicolon end; space indentation; case; comment)

04 CRUD operation of the database

SQL classification

DDL_Operation Database_Create & Query

Query database

Create database

DDL_Operation Database_Modify&Delete&Use

Modify the database

Delete database

Use database


03 SQL basic concepts and general syntax

1. What is SQL?
    Structured Query Language: The structured query language
    actually defines the rules for operating all relational databases. Each way of database operation is different, which is called "dialect".
    
2. SQL general syntax
    1. SQL statements can be written in single or multiple lines, ending with a semicolon.
    2. Spaces and indentation can be used to enhance the readability of sentences.
    3. The SQL statements of the MySQL database are not case-sensitive. It is recommended to use uppercase for keywords.
    4. 3 kinds of comments
        * Single line comment: - Comment content or # comment content (mysql-specific) 
        * Multi-line comment: /* Comment*/
    
3. SQL classification
    1) DDL (Data Definition Language) data definition language is
        used to define the database Object: database, table, column, etc. Keywords: create, drop, alter, etc.
    2) DML (Data Manipulation Language) data manipulation language is
        used to add, delete, and modify data in the tables in the database. Keywords: insert, delete, update, etc.
    3) DQL (Data Query Language) is
        used to query the records (data) of tables in the database. Keywords: select, where, etc.
    4) DCL (Data Control Language) data control language (understand)
        Used to define database access rights and security levels, and create users. Keywords: GRANT, REVOKE, etc.

SQL general syntax (semicolon end; space indentation; case; comment)

  

04 CRUD operation of the database

SQL classification

SQL classification

  • 1) DDL (Data Definition Language) data definition language: used to define database objects: databases, tables, columns, etc. Keywords: create, drop, alter, etc.
  • 2) DML (Data Manipulation Language) data manipulation language: used to add, delete and modify the data in the database table. Keywords: insert, delete, update, etc.
  • 3) DQL (Data Query Language) data query language: used to query the records (data) of the tables in the database. Keywords: select, where, etc.
  • 4) DCL (Data Control Language) data control language (understanding): used to define database access rights and security levels, and create users. Keywords: GRANT, REVOKE, etc.

DDL_Operation Database_Create & Query

1. Operating database: CRUD

    1. C(Create): Create

        * Create database: create database database name;

        * Create a database, determine that it does not exist, and then create: create database if not exists database name;

        * Create a database and specify the character set: create database database name character set character set name;

        * Exercise: Create a db4 database, determine whether it exists, and set the character set to gbk: create database if not exists db4 character set gbk;

    2. R(Retrieve): query

        * Query the names of all databases: show databases;

        * Query the character set of a database (query the creation statement of a database): show create database database name;

    3. U(Update): modify

        * Modify the character set of the database: alter database database name character set character set name;

    4. D(Delete): delete

        * Delete database: drop database database name;

        * Determine if the database exists, and then delete it: drop database if exists database name;

    5. Use the database

        * Query the name of the database currently in use: select database();

        * Use database: use database name;

  • information_schema: Describes the MySQL database information (what tables are there, and what libraries are there). The databases and data tables in this library are not real databases or data tables (views), and there is no real target file.
  • mysql: MySQL core database, which stores a lot of core data.
  • performance_schema: The database that performs operations on performance improvement. [Information_schema, mysql, performance_schema these three databases, try not to touch them!
  • test: Test database, empty database, can be used at will.

Query database

Create database

DDL_Operation Database_Modify&Delete&Use

Modify the database

Delete database

Use database

Query the name of the database currently in use: select database();

Use database: use database name;

Guess you like

Origin blog.csdn.net/weixin_44949135/article/details/113521178