热门:网页模板.net视频教程JQueryMVCjsonExtJs源码示例三级联动JQuery菜单
您现在的位置:.Net中文社区>> 数据库>>正文内容

项目中常用sql语句

发布时间:2010年05月26日点击数: xiaoxiaoniao

1:随机取出数据表中数据

select top n * from table order by newid()

2:取出插入表中的最新ID

insert into table vlues() select @@identity

3:取出表中10-20的数据

select top 10 * from table where id not in(select top 20 id from table)

4:判断字段并赋于不同值

select columnName1=

case columnName1

when 1 then 'value'

end

from table

5:获取最后更新时间的所有列

select  max(addDate) ,userName from table group by userName order by addDate desc

6:删除表中所有重复记录

delete from table where columnName =(select columnName from table group by columnName

having count(*)>1)

7:获取日期和时间

select  convert(char(20),getDate(),20) value from table
select  convert(char(8),getDate(),108) value from table

本站热点业务

更多模板/案例展示

关于我们 | 联系我们 | 团队日志 | 网站地图 | 网站合作