温馨提示×

常用的mysql命令语句有哪些

小亿
92
2023-06-05 16:35:39
栏目: 云计算

  1. 创建数据库:CREATE DATABASE database_name;

  2. 删除数据库:DROP DATABASE database_name;

  3. 选择数据库:USE database_name;

  4. 创建表:CREATE TABLE table_name (column_name1 data_type1, column_name2 data_type2, …);

  5. 删除表:DROP TABLE table_name;

  6. 插入数据:INSERT INTO table_name (column_name1, column_name2, …) VALUES (value1, value2, …);

  7. 更新数据:UPDATE table_name SET column_name1 = value1, column_name2 = value2 WHERE condition;

  8. 删除数据:DELETE FROM table_name WHERE condition;

  9. 查询数据:SELECT column_name1, column_name2, … FROM table_name WHERE condition;

  10. 查询表结构:DESCRIBE table_name;

  11. 添加主键:ALTER TABLE table_name ADD PRIMARY KEY (column_name);

  12. 添加外键:ALTER TABLE table_name ADD FOREIGN KEY (column_name) REFERENCES other_table(column_name);

  13. 修改表结构:ALTER TABLE table_name MODIFY column_name data_type;

  14. 清空表数据:TRUNCATE TABLE table_name;

  15. 查看当前版本:SELECT VERSION();

0