Mysql中curd基础以及B+Tree原理

一.MYSQL中增删改查

  在mysql的crud中,查询操作一般会比较偏多,所涉及的查询操作比较多,有单表查询,联合查询,关联查询等等
“”@[TOC](目录一)"

1.基础查询

1.1单表查询和关联查询
select  field1(字段一) f1(字段一别名),field2(字段二) from table(表名) as t1  where  t1.id=""
select field1 from table1 as t1 left join  table2 t2 on t1.id=t2.t_id
1.2联合查询
select id as no, field1 f1, f2 from table1 union select * from table2 order by no desc;

  如果第一个select语句中的列有别名,则order by子句中就必须使用该别名,因为id此时被民名为no,如果直接使用id则会提示没有此列,拼接规则是以第一张表字段为主

2.Insert into插入数据

mysql中插入数据命令

insert into table(field1, field2, field2) values('v1', 'v2', 'v3')
insert into my_test(name,age, sex) values('alice', 29, 'man')

3.Update更新数据

update my_test set name='王心',age=15, sex='woman' where id=4;

4.Delete删除操作

  • 小知识:清空表之后将自增id重新设置回1
    alter table table_name(表名) auto_increment=1
  • 使用truncate清空表
    truncate test; 使用truncate清空表后自增id也会重新被置为1
delete from table where id='xx'

二.Mysql中索引原理

未完待续

猜你喜欢

转载自blog.csdn.net/qq_42707967/article/details/108659600