# 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;
    ```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://1425816423.gitbook.io/my-knowledge-base/fu-wu-qi-duan/shu-ju-ku/mysql-chang-jian-yu-fa.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
