数据库表记录操作

数据库

操作表记录 :

增 :

	- insert into 表名 (列1,列2) values (值1,值2);

删 :

-delete from 表名 where 条件 ;

-delete from 表名 ;删除表中所有的数据

- delete from 表名 where id >9 and id <20;

-truncate 表名 (没有where 条件)

区别 :

1. delete之后,插入数据从上一次主键自增加1开始, truncate则是从1开始
2. delete删除, 是一行一行的删除, truncate:全选删除 truncate删除的速度是高于delete的

查 ;

-select 列1,列2 from 表名 + where

  • select * from 表名 + where

  • between ....and... 取值范围是闭区间

  • distinct 避免重复 select distinct name 表名去重

  • like : 模糊查询

  • -以x 开头:

  • select * from 表名 where name like 'x%';

  • --以x结尾 :

  • select * from 表名 where name like '%x';

  • --- 包含x :

  • #### select * from 表名 where name like '%x%'; 
    

    in() 取in 范围内的值 --> n

    select * from 表名 where id in (n);

  • #### 通过四则运算查询 (不要用)--》 列改变
    

    select name, age*10 from 表名;

改 :

-update 表名 set 列名1=新值1,列名2=新值2 where 条件;

---update 表名 set name= ‘xxx’ where id>20 and id<32;

原文地址:https://www.cnblogs.com/shaozheng/p/11759756.html