zoukankan      html  css  js  c++  java
  • 常用SQL语句的整理--SQL server 2008(查询一)

    表的创建和表结构的修改我们这里就不说了,主要是说说查询语句和一些常用的语句

    --更新语句操作,主要想说明的就是,在中文字符前面最好加上N,以防止出现乱码

    update gb_data set username=N'天才夏雨' where id=5

    --新增一条语句,并且立刻获取他的主键id(这个用的很多啊,比如餐厅管理)

    insert into gb_data( username, body, ip) values ('xiayu222','ewdfdf','172.1.1.0');select @@IDENTITY

    --查询语句十分强大,几乎可以查任何东西

    --查询SqlServer版本

    select @@VERSION as 版本

     --查询日期

    select GETDATE()as 日期

    下面我们来重点说说查询语句

    --查询符合条件的记录

    select *from gb_data where username='夏雨'

    --查询对表进行排序后的操作(order by)

    select *from gb_data order by createdate,username

    --order by语句一定要放在where语句后面(否则会报错 ---关键字 'where' 附近有语法错误。)

    select *from gb_data where username='夏雨' order by createdate

    --模糊查询用like关键字,_表示一个字符,%表示多个字符

    select *from gb_data where username like '%雨%'
    select *from gb_data where username like '_雨%'

    注:NULL表示“不知道”,有NULL参与的运算结构一般都为NULL,查询数据是否为NULL,不能用=,!=,要用IS关键字

    --查询某一个范围内的数据可以用IN关键字

    select * from person where age in(18,19,20)
  • 相关阅读:
    kuangbin带你飞 并查集 题解
    kuangbin带你飞 最短路 题解
    kuangbin带你飞 后缀数组 题解
    Kuangbin 带你飞-线段树专题 题解
    HDU 4578 Transformation
    Tarjan & LCA 套题题目题解
    Dancing Links [Kuangbin带你飞] 模版及题解
    二分匹配 大白例题虽有代码
    编程范式:响应式编程
    编程结构:Promise和Future
  • 原文地址:https://www.cnblogs.com/guyali/p/5376419.html
Copyright © 2011-2022 走看看