Mysql常见语法

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

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

  1. 创建数据库:

    CREATE DATABASE database_name;
  2. 选择数据库:

    USE database_name;
  3. 创建表:

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

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

    SELECT column1, column2, ...
    FROM table_name
    WHERE conditions;
  6. 更新数据:

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

    DELETE FROM table_name
    WHERE conditions;
  8. 添加列:

    ALTER TABLE table_name
    ADD column_name datatype constraints;
  9. 修改列:

    ALTER TABLE table_name
    MODIFY column_name datatype constraints;
  10. 删除列:

    ALTER TABLE table_name
    DROP COLUMN column_name;
  11. 创建索引:

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

    DROP INDEX index_name
    ON table_name;