常用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)

 

posted on 2016-04-11 13:30  一杯特仑苏  阅读(1660)  评论(0编辑  收藏  举报

导航