侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130555 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

mysql基本操作-数据表操作

2024-05-10 星期五 / 0 评论 / 0 点赞 / 8 阅读 / 1978 字

1.创建数据表create table table_name( id int not null auto_increment, name char not null, age int

1.创建数据表

create table table_name(    id int not null auto_increment,    name char not null,    age int not null,    register_date date,    primary key(id);)

2.插入数据(增)

insert into table_name (name,age,register_date) values ("mxm",23,"2018-07-13");

3.查询数据表(查)
3.1.查询全部数据

select * from table_name

3.2.查询条件

select column_name,column_name from table_name[where 条件][limit n][offset m]

3.3.offset 从m行开始查必须和limit一起用

select * from table_name limit 2 offset 2

3.4.where条件
年龄大于23的:

select * from table_name where age>23;

年龄大于23的并且id大于2的:

select * from table_name where age>23 and id>2;

3.5.模糊查询like
注册日期在2018-07的:

select * from table_name where register_data like "2018-07%";

4.修改数据(改)
修改第一条数据的name列为m_x_m

update table_name set name="m_x_m" where id=1;

5.删除数据(删)
删除id等于1的数据

delete from table_name where id=1;

6.排序asc/desc
按id排序

select from table_name order by id asc;

7.分组group by
按注册日期和统计数据查询名字对应的相同日期注册个个数

select name,cout(*) from table_name group by register_date;

---------- alter字段操作--------------------------
8.添加字段

alter table table_name add sex enum('0','1');

9.删除字段

alter table table_name drop sex;

10.修改字段

alter table table_name modify sex enum('0','1') not null;

广告 广告

评论区