Some commonly used sql statements of mysql

First enter cmd to open the terminal, then cd to the bin folder of mysql, then enter MySQL -u root -p and then prompt for a password, and enter the database after entering the password. You can operate the database.

Before creating a database in mysql, you can use the show statement to display the currently existing database, show databases

                            

Use create database test2 to create the database

                            

Use use database_name (database_name represents the name of the database) to select the database to use.

                             

Use drop database database_name to delete the database.

                             

Use show engines to view the storage engines supported by the database. You can also use show engines \ g or show variables like 'have%'

The storage engine refers to the type of table. In specific development, in order to improve the efficiency and flexibility of the MySQL database management system, you can choose the storage engine according to actual needs, because the storage engine specifies the type of table, that is, how to store and index data, whether to support transactions, etc., while storing The engine also determines how the table is stored in the computer. It can be known that MySQL supports 9 storage engines. The understanding of the table is as follows: First, the 'engine' parameter indicates the name of the storage engine; 'support' indicates whether the mysql database management system supports the engine, 'yes' indicates support, 'no' indicates not supported, and 'default' indicates that the system supports the default Storage engine; 'comment' parameter indicates comments on the storage engine, 'transactions' indicates whether the storage engine supports transactions, 'XA' indicates whether the storage engine supports distributed compliance with XA specifications, 'savepoints' indicates whether the storage engine supports transaction processing Savepoint.

Use show variables like 'storage_engine'; to view the default storage engine,

                           

Use set default_storage_engine = myisam; to modify the default storage engine

Table operation: The database in the table contains columns, indexes and triggers.

Column: also known as field: attribute column, when creating a table, you must specify the name and data type of the column; index: according to the order in which the specified database table column is established, it provides a quick access to data and can supervise the table data , So that the data in the column it points to is not repeated; trigger: a user-defined set of transaction commands, when the data in a table is inserted, updated, or deleted, this set of commands will be automatically executed and can be used to ensure data Integrity and security.

Syntax form for creating tables

create table tablename(
    属性名 数据类型 [完整性约束条件],
    属性名 数据类型 [完整性约束条件],
    ...
    属性名 数据类型 [完整性约束条件]);

                                                    

There are two ways to view the structure of the table. Viewing the structure of the table refers to viewing the definition of the existing table in the database.

The first type: describe statement to view the table definition. The describe statement can view the basic definition of the table, which contains the field name, field data type, whether it is the primary key and the default value.

Statement syntax form:

describe tablename;

                       

Where field indicates the field, type indicates the data type, null indicates whether it is empty, key indicates whether it is the primary key, default indicates the default value, and extra indicates additional information

The second is the detailed information definition of the show create table statement query table . grammar

show create table tablename;

                                            

Later, it will gradually improve.

Published 148 original articles · Like 10 · Visitors 20,000+

Guess you like

Origin blog.csdn.net/ab1605014317/article/details/103994184