文章分类 -  SqlServer

sql 多条件查询的一种简单的方法
摘要:以后我们做多条件查询,一种是排列结合,另一种是动态拼接SQL如:我们要有两个条件,一个日期@addDate,一个是@name第一种写法是if (@addDate is not null) and (@name '')select * from table where addDate = @addDate and name = @nameelse if (@addDate is not null)... 阅读全文

posted @ 2005-06-30 14:40 Martin XJ 阅读(720) 评论(1) 推荐(0)

SQL server 动态SQL对变量讲行赋值
摘要:执行如下SQL declare @t int exec('set @t=1') print(@t) 报如下错误! 服务器: 消息 137,级别 15,状态 2,行 1 必须声明变量 '@t'。 实际就是变量与动态语句不能共享, 那么换成这样就行, declare @t int set @t=1 print(@t) 或 exec('declare @t int; set @t=... 阅读全文

posted @ 2005-06-30 14:29 Martin XJ 阅读(1196) 评论(0) 推荐(0)

清理SQL SERVER事务日志
摘要:backup log db_name with no_log dbcc shrinkfile (northwind_log,5) 阅读全文

posted @ 2005-06-30 14:19 Martin XJ 阅读(479) 评论(0) 推荐(0)

精妙SQL语句
摘要:说明:复制表(只复制结构,源表名:a 新表名:b) SQL: select * into b from a where 11说明:拷贝表(拷贝数据,源表名:a 目标表名:b) SQL: insert into b(a, b, c) select d,e,f from b;说明:显示文章、提交人和最后回复时间 SQL: select... 阅读全文

posted @ 2005-06-30 14:17 Martin XJ 阅读(397) 评论(0) 推荐(0)

自动备份SQL Server数据库中用户创建的Stored Procedures
摘要:为了避免意外丢失/损坏辛苦创建的Stored Procedures,或者想恢复到以前版本的Stored Procedures,这样提供了一个有效方法,可以自动将指定数据库中的Stored Procedures进行备份。 1. 在特定的数据库(建议为SQL Server的master数据库)上创建数据表StoredProceduresBackup,用来保存备份的Stored Procedures... 阅读全文

posted @ 2005-06-30 14:17 Martin XJ 阅读(484) 评论(0) 推荐(0)

存储过程事务处理
摘要:declare @Error intbegin transet @Error=0select @DeptName=DeptName from B_Dept where DeptNo=@DeptNoset @Error=@Error+@@Errorif @Error0 begin rollbackend elsebegin commitend GO 阅读全文

posted @ 2005-06-30 13:59 Martin XJ 阅读(719) 评论(0) 推荐(0)

动态游标
摘要:CREATE PROCEDURE WGetMaxNo @TableName varchar(20),@FieldName varchar(20) ASdeclare @MaxNo varchar(10)declare @aa intdeclare @bb varchar(10)declare @sql nvarchar(500) set @sql='declare W... 阅读全文

posted @ 2005-06-30 13:56 Martin XJ 阅读(407) 评论(0) 推荐(0)

存储过程编写经验和优化措施
摘要:一、前言:在经过一段时间的存储过程开发之后,写下了一些开发时候的小结和经验与大家共享,希望对大家有益,主要是针对Sybase和SQL Server数据库,但其它数据库应该有一些共性。 二、适合读者对象:数据库开发程序员,数据库的数据量很多,涉及到对SP(存储过程)的优化的项目开发人员,对数据库有浓厚兴趣的人。 三、介绍:在数据库的开发过程中,经常会遇到复杂的业务逻辑和对数据库的操作,这个时候... 阅读全文

posted @ 2004-08-26 09:03 Martin XJ 阅读(526) 评论(0) 推荐(0)

备份事务日志的存储过程
摘要:------------------------------------------------------------------------------------------------------ OBJECT NAME : isp_Backup_TLog---- AUTHOR : Tara Duggan-- INPUTS : @Path ... 阅读全文

posted @ 2004-08-12 18:27 Martin XJ 阅读(642) 评论(0) 推荐(0)

Top 10 Cool Things about SQL Server 2005 Express Edition
摘要:You've probably already heard by now about SQL Server 2005 Express Edition. It's the next evolution of MSDE 2000. Here's the Top 10 Cool Things about SQL Server 2005 Express Edition: Integrated co... 阅读全文

posted @ 2004-08-12 18:26 Martin XJ 阅读(508) 评论(1) 推荐(0)

备份数据库的存储过程
摘要:------------------------------------------------------------------------------------------------------ OBJECT NAME : isp_Backup---- AUTHOR : Tara Duggan-- DATE : December 18,... 阅读全文

posted @ 2004-08-12 18:23 Martin XJ 阅读(702) 评论(0) 推荐(0)