当前位置: 代码网 > it编程>数据库>Mysql > MYSQL 常用语句速查(最新整理)

MYSQL 常用语句速查(最新整理)

2024年12月25日 Mysql 我要评论
好的,按照你的要求,调整后的表格如下:好的,我已经在表级操作中新增了查看某一张具体表的操作,以下是更新后的表格:级别操作类型sql 语句示例库级增create databasecreate datab

好的,按照你的要求,调整后的表格如下:

好的,我已经在表级操作中新增了查看某一张具体表的操作,以下是更新后的表格:

级别操作类型sql 语句示例
库级create databasecreate database mydb;
库级show databasesshow databases;
库级drop databasedrop database mydb;
库级alter databasealter database mydb character set utf8mb4 collate utf8mb4_unicode_ci;
表级create tablecreate table users (id int auto_increment, name varchar(100), age int, primary key(id));
表级show tablesshow tables;
表级describe table_namedescribe users;
表级drop tabledrop table users;
表级alter tablealter table users add column email varchar(100);
字段级alter table add columnalter table users add column email varchar(100);
字段级describedescribe users;
字段级alter table drop columnalter table users drop column email;
字段级alter table modify columnalter table users modify column age int not null;
数据级insert intoinsert into users (name, age) values ('alice', 30);
数据级selectselect * from users;
数据级select ... whereselect * from users where age > 25;
数据级updateupdate users set age = 31 where name = 'alice';
数据级delete fromdelete from users where name = 'alice';

详细说明:

库级操作:

  • create database:创建一个新的数据库。
  • show databases:查看当前 mysql 服务器上的所有数据库。
  • drop database:删除指定的数据库。
  • alter database:修改数据库的属性(如字符集、排序规则等)。

表级操作:

  • create table:创建一张新的表。
  • show tables:查看当前数据库中的所有表。
  • drop table:删除指定的表。
  • alter table:修改表的结构(例如添加列、删除列、修改列类型等)。
  • describe table_name:查看某一张具体表的结构,包括列名、数据类型、默认值、是否允许为 null 等。

字段级操作:

  • alter table add column:向表中添加一个新字段。
  • describe:查看表的结构,包含列信息、数据类型、默认值等。
  • alter table drop column:删除表中的某一列。
  • alter table modify column:修改表中某一列的类型、大小或其他属性。

数据级操作:

  • insert into:向表中插入一条新的记录。
  • select:查询表中的数据,支持不同的过滤和排序条件。
  • select ... where:根据条件查询特定的记录。
  • update:更新表中现有的记录。
  • delete from:删除表中的记录。

这样修改后,表格中各个操作级别(库级、表级、字段级、数据级)已经符合你的要求。

到此这篇关于mysql 常用语句速查的文章就介绍到这了,更多相关mysql 常用语句速查内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com