摘要: createtabletest(idint,namevarchar(10),parentidint)select*fromtestinsertintoTestvalues(1,'aa',-1)insertintoTestvalues(2,'aa',-1)insertintoTestvalues(3,'aa',1)insertintoTestvalues(4,'aa',1)insertintoTestvalues(5,'aa',3)declare@idint=1;withTestCTEas(select*fromte 阅读全文
posted @ 2012-05-12 16:46 紫詪 阅读(74) 评论(0) 推荐(0) 编辑
摘要: 代码Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--1--当前月的第一天2SELECTDATEADD(month,DATEDIFF(month,0,getdate()),0);34--当前月的最后一天5SELECTDATEADD(month,DATED... 阅读全文
posted @ 2009-12-22 13:13 紫詪 阅读(100) 评论(0) 推荐(0) 编辑
摘要: 设置数据库为完整模式alterdatabasedbsetrecoveryfull对数据库进行完整备份backupdatabasedbtodisk='d:\tmp\db.bak'withformat误操作后备份数据库日志文件backuplogdbtodisk='d:\tmp\db_log.bak'WITHFORMAT还原数据库文件backuplogdbtodisk='d:\tmp\db_log.ba... 阅读全文
posted @ 2009-10-13 17:50 紫詪 阅读(515) 评论(0) 推荐(0) 编辑
摘要: with别名 as( select * from Tmp)select * from 别名CTE后面必须直接跟使用CTE的SQL语句(如select、insert、update等),否则,CTE将失效多个with 写法with别名 as( select * from Tmp),with别名 as( select * from Tmp) 阅读全文
posted @ 2009-08-06 12:06 紫詪 阅读(342) 评论(1) 推荐(0) 编辑
摘要: 语法规则聚合函数|排名函数 over(PARTITION BY 字段 order by 字段) PARTITION BY 将结果集分为多个分区。 开窗函数分别应用于每个分区,并为每个分区重新启动计算。排名函数(ROW_NUMBER、DENSE_RANK、RANK、NTILE)例句聚合函数: SELECT *,sum(tmp) OVER(PARTITION BY tmp) AS RowTmp FRO... 阅读全文
posted @ 2009-08-06 11:51 紫詪 阅读(226) 评论(0) 推荐(0) 编辑