• SQL 增删改查(具体)


    一、增:有3种方法

    1.使用insert插入单行数据:

       insert [into] <表名> [列名] values <列值>
    
      insert into Strdents (name,age) values ('atm',12)

    2.使用insert,select语句将现有表中的 数据加入到已有的新表中

       insert into <已有的新表> <列名> select <原表列名> from <原表名>
    
      insert into newtable (name,class)select name,class from  tableinfo

    3.将数据插入原表中(生成測试数据用的较多)

        和另外一种方法一样,仅仅是拷贝到原表中
    
       insert into tableinfo ('name','class')select name,class from  tableinfo

    二、删:有3中方法

    1.delete删除

        delete from <表名> [where <删除条件>]    
    
        delete from tableinfo where name='atm'

    2.truncate table 删除整个表的数据

         truncate table <表名>
    
        truncate table tableinfo
    
       删除表的全部行。但表的结构、列、约束、索引等不会被删除;不能用于有外建约束引用的表

    3、drop删除

        drop table <表名>
        drop table tableinfo
       删除表中全部行。表结构也删除了。

    三、update更新改动

        update <表名> set <列名=更新值> [where <更新条件>]
        update tableinfo set age=12 where name='atm1'
       set后面能够紧随多个数据列的更新值(非数字要引號);

    四、查

    1.普通查询

      select <列名> from <表名> [where <查询条件表达试>] [order by <排序的列名>[ascdesc]]
    
        1).查询全部数据
    
        select * from tableinfo
    
       2).查询部分行列--条件查询
    
        select name,age   from  tableinfo   where age=11;
    
       3).在查询中使用AS更改列名
    
        select name as 姓名 from a where  age=11;
    
       4).查询空行
    
        select name from tableinf  where class is null
    
         5).查询返回限制行数(关键字:top )
    
        select top 6 name from tableinfo
    
        显示列name的前6行,oracle 中用rownum替代(select   *   from   a where   rownum<6 )
        
       6).查询排序(关键字:order by , asc , desc)
    
        例:select name from tableinfo where age>=11 order by desc(默觉得ASC升序)

    2.模糊查询

       1).使用like进行模糊查询
    请看还有一篇文章, SQL like四种使用方法
        
       2).使用between在某个范围内进行查询

    select * from tableinfo where age between 11 and 22

      
       3).使用in在列举值内进行查询(in后是多个的数据)

    select name from tableinfo where name in ('atm','atm1','atm2');
  • 相关阅读:
    40个GitHub上最受欢迎的iOS开源项目
    Swift应用开源项目推荐
    swift在github上开源的地址
    必须Mark!43个优秀的Swift开源项目推荐
    Swift中编写单例的正确方式
    Android提高第十一篇之模拟信号示波器
    Android平台音频信号FFT的实现
    ios UINavigationController
    工作记录8:iOS 传值问题总结(7种传值完美介绍)
    利用协议代理实现导航控制器UINavigationController视图之间的正向传值和反向传值
  • 原文地址:https://www.cnblogs.com/jhcelue/p/7015623.html
Copyright © 2020-2023  润新知