常⽤SQL语句的整理--SQLserver2008(查询⼀)表的创建和表结构的修改我们这⾥就不说了,主要是说说查询语句和⼀些常⽤的语句
--更新语句操作,主要想说明的就是,在中⽂字符前⾯最好加上N,以防⽌出现乱码
常用的sql查询语句有哪些
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)