# Mysql常见语法

status: Idea tags: 数据库 Created time: August 27, 2023 9:59 PM

MySQL是一个常用的关系型数据库管理系统，下面列举一些MySQL常用的语法：

1.  创建数据库：

    ```sql
    CREATE DATABASE database_name;
    ```
2.  选择数据库：

    ```sql
    USE database_name;
    ```
3.  创建表：

    ```sql
    CREATE TABLE table_name (
      column1 datatype constraints,
      column2 datatype constraints,
      ...
    );
    ```
4.  插入数据：

    ```sql
    INSERT INTO table_name (column1, column2, ...)
    VALUES (value1, value2, ...);
    ```
5.  查询数据：

    ```sql
    SELECT column1, column2, ...
    FROM table_name
    WHERE conditions;
    ```
6.  更新数据：

    ```sql
    UPDATE table_name
    SET column1 = value1, column2 = value2, ...
    WHERE conditions;
    ```
7.  删除数据：

    ```sql
    DELETE FROM table_name
    WHERE conditions;
    ```
8.  添加列：

    ```sql
    ALTER TABLE table_name
    ADD column_name datatype constraints;
    ```
9.  修改列：

    ```sql
    ALTER TABLE table_name
    MODIFY column_name datatype constraints;
    ```
10. 删除列：

    ```sql
    ALTER TABLE table_name
    DROP COLUMN column_name;
    ```
11. 创建索引：

    ```sql
    CREATE INDEX index_name
    ON table_name (column1, column2, ...);
    ```
12. 删除索引：

    ```sql
    DROP INDEX index_name
    ON table_name;
    ```
