经典SQL语句收藏
以下是我平时在工作中收藏的一些觉得有用的SQL语句,共大家使用
1.一句SQL语句获得当月天数:
select Day(dateadd(day,-1,convert(datetime,convert(char(07),dateadd(m,1,getdate()),120)+ '-01 ')))
select 32-Day(getdate()+(32-Day(getdate())))
2.说明:选择从10到15的记录:
select top 5 * from (select top 15 * from tableName order by id asc) table_别名 order by id desc
3.返回库中用户表:
select * from sysobjects where xtype='U'
4、说明:删除重复记录:
Delete from tablename here id not in (select max(id) from tablename group by col1,col2,...)
5.新建一个与a表一样的空的b表:
方法二:select * into b from a where 1 <> 1
方法二:select top 0 * into b from a
6.说明:两张关联表,删除主表中已经在副表中没有的信息
delete from table1 where not exists ( select * from table2 where table1.field1=table2.field1 )
不断更新中...
- 评论
-
- [使用Ctrl+Enter键可以直接提交]
表情图标
Advertise
Category
Time Counter
离十一还有
Recent Article
- 1.亦舒经典作品语录
- 2.工作笔记:AS3加载外部图片,有加载百分比
- 3.document.documentElement和document.body的区别
- 4.100种增加网站流量的方法
- 5.用div+css模拟表格对角线
- 6.如何做一个好的技术型领导
- 7.苍井空是谁?
- 8."心态"新解
- 9.程序员特有的9个坏习惯
- 10.AS3入门之简单Loading效果
- 11.系统问题:浏览器无法打开png图片
- 12.AS3中以post和get方式提交数据
- 13.defaultTextFormat和setTextFormat()区别
- 14.AS3中超方便地遍历xml
- 15.pv3d中物体常用的移动属性
- 16.开源Flash 3D引擎Papervision3d
- 17.as3 判断鼠标滚轮前滚或后滚
- 18.js:行向上替换滚动效果
- 19.为什么要清净?(禅与佛)
- 20.扩展window.setTimeout方法



