随笔分类 -  4 SQL

公用表表达式(CTE)WITH:树型查询、更新
摘要:转自http://msdn.microsoft.com/zh-cn/library/ms175972(SQL.100).aspx指定临时命名的结果集,这些结果集称为公用表表达式 (CTE)。语法:[ WITH <common_table_expression> [ ,...n ] ]<common_table_expression>::=expression_name[ (... 阅读全文

posted @ 2010-07-22 14:42 NewSunshineLife 阅读(399) 评论(0) 推荐(0)

将十六进制字符串转换为Varbinary
摘要:转自http://sqlblog.com/blogs/peter_debetta/archive/2007/03/09/t-sql-convert-hex-string-to-varbinary.aspxSQL Server 2005中有一个没有文档说明的函数sys.fn_varbintohexstr,函数可把十六进制数转换为字符串表示的十六进制数(例如0x3a转换为'0x3a'),但是并没有函数... 阅读全文

posted @ 2010-05-24 14:01 NewSunshineLife 阅读(681) 评论(0) 推荐(1)

数字前加0补齐
摘要:使用RIGHT ( character_expression , integer_expression ) 返回字符串中从右边开始指定个数的字符。例如:SELECT RIGHT('FirstName', 5) AS 'First Name' --- tNameselect RIGHT ('000000' + cast ( 1 as varchar(6) ), 6)--- 000001select ... 阅读全文

posted @ 2010-05-22 16:14 NewSunshineLife 阅读(529) 评论(0) 推荐(0)

得到当前数据库所有表的信息
摘要:SELECT * FROM sys.sysobjects WHERE xType = 'U' ORDER BY name ASCxType类型AF = Aggregate function (CLR)C = CHECK constraintD = DEFAULT (constraint or stand-alone)F = FOREIGN KEY constraintFN = SQL scalar... 阅读全文

posted @ 2010-05-11 11:58 NewSunshineLife 阅读(183) 评论(0) 推荐(0)

不显示触发器中的Rollback Tran的出错信息
摘要:触发器中使用Rollback Tran来取消要执行的操作,但是这样会显示错误提示信息:ALTER TRIGGER TestTriggerON TestTableFOR INSERT AS ROLLBACK TRANINSERT INTO TestTable VALUES ( 4 )Msg 3609, Level 16, State 1, Line 2The transaction ended in... 阅读全文

posted @ 2010-05-10 14:03 NewSunshineLife 阅读(527) 评论(0) 推荐(0)

导航