zoukankan      html  css  js  c++  java
  • 数据库的增删改查

    数据的基本操作:增(insert)删(delete)改(update)查(select);

    1.添加数据(insert)

      insert into 表名(字段名1,字段名2) values (数据1,数据2);

      insert into 表名(name,tid) values ('李白','王维');

      insert into 表名(name,tid) values (''李白,'王维'),(''杜甫,'孟浩然'); 这是插入多条数据

      字段名和数据要一一对应;

      字符串和时间日期类型用单引号引起来;

      字段可以省略,但是要按顺序全字段数据插入;

    2.数据的删除(delete)

      delete from 表名 删除表中的所有数据但是id不会重置

      truncate 表名: 删除表中所有数据,标识所用值重置;

      delete from grade where id=4;  加上限制条件 where可以就指定删除哪一行

    3.修改(update)

       update 表名 set 字段名=新值 [where id = 3];

      update grade set name='zhangsan';     这样写就把name字段下面数据全更改了

      update grade set name='php' where id =1; 这样写是指定name字段下的id是1的哪一行更改数据

      update grade set name='php',title='aaa'  where id =1; 这是修改多条字段的信息

    4.查询(select)

      select * from 表名;

      select *from grade; 这是查询表中所有字段下的数据

            

      select 字段1,字段2 from 表名

      select name,tid from grade;这是查询字段name和tid下的数据

           

      select 字段1 as ‘新名字’,字段2 as ‘新名字' from 表名

      select name as '姓名' , tid as '学号' from grade;  查询出来的结果给name和tid起个新名字显示;

         

    4.1where条件(逻辑and or 比较>、<、=、>=、<=、<>不等于)

      select * from 表名 where 字段1>值 and 字段2<值;

      select*from grade where chengji>=10 and chengji<=15;

           

      (1).where条件中between and   这个其实就是等于 chengji>=10 and chengji<=15;

      select * from 表名 where 字段 between 75 and 90;

      select*from grade where chengji between 10 and 20;

           

      (2).空条件查询

      select * from 表名 where 字段 IS NULL;(IS NOT NULL)

      select*from grade where chengji IS NULL;

     

  • 相关阅读:
    Hive内部表外部表转化分析
    20130515
    mapred.local.dir
    经典
    hive中巧用正则表达式的贪婪匹配
    做生意十大忌
    股价是最没有用的东西,要看公司基本面和盈利
    textView文本不同颜色
    Android中扫描wifi热点
    android 与 PC的socket通信
  • 原文地址:https://www.cnblogs.com/sheep-fu/p/12990808.html
Copyright © 2011-2022 走看看