美文网首页
表内容的增删改查

表内容的增删改查

作者: 恬恬i阿萌妹O_o | 来源:发表于2018-08-09 08:21 被阅读0次

    crud  对表的增删改查
    增 insert into
    1.完全插入:例如:insert into 表名 values( 108401,' 小甜甜 ', 20,1,' 1245678999 ');
    2.选择插入:例如:insert into 表名(userid,name,age) values( 10000,' 花花 ',19);
    3.多行插入:例如:insert into 表名(userid,name) values(19999,' 葡萄 '),(18888,‘ 辣椒 ’);
    查看已经插入的数据 select * from 表名 (*表示所有);
    修改 跟新 update
    1.跟新单个字段(列)
    update 表名 set name = '娜娜' , age = 19 where id = 12345;
    2.跟新多行
    update 表名 set name = ' 娜娜 ' ;
    3.跟新多个字段(列)
    update 表名 set name = ' 娜娜 ' age = 19 where id = 18888 ;
    将一个表复制到另一个表中
    insert into 新表 (列名,列名...) select 列名,列名... from 原表 ;
    删除数据 delete
    删除特定的一行:例如:delete from 表名 where id = 10010 ;
    删除所有行:例如:delete from 表名 (不能轻易做);
    查询
      查询所有 select * from 表名 ;
      查询某一个 select * from 表名 where id = 13333 ;
      查询年龄这个列 select age from 表名 where id = 19999;
    使用限定的方式查找,不进入数据库就可以查询到表的信息
      select * from 数据库名.表名;
    使用 distinct 去重,返回不重复的列的值
      select distinct age from 表名;insert into 表 (列名,列名...) select 列名,列名... from 表
    数据库的查询 where(过滤)
      查询一行 select * from 表名 where age = 6 ;
    where 条件查询和运算符 
      = 等于 select * from 表名 where age = 6 ;
    <> 不等于, != 不等于,
      < 小于, <= 小于等于, > 大于, >= 大于等于,
      between ... and 在两者之间(包含边界值);
    例如:select name ,age from 表名 where age between 5 and 30 ;
      is null 判断某一列的数据,如果包含null ,则返回记录;
      例如:select * from 表名 where phone is null ;
    and 链接查询条件,查询的数据要全部满足
      例如:select name from 表名 where userid>=18004 and age>99;
    or 链接查询条件,查询的数据只要满足其中一个即可
      例如:select name from 表名 where userid>=18004 or age>90;
    in 操作符 (相当于 or ) in (条件1,条件2,条件3);
      例如:selete name(列)

    相关文章

      网友评论

          本文标题:表内容的增删改查

          本文链接:https://www.haomeiwen.com/subject/hamfbftx.html