常用的数据库代码
2010-03-26 13:42 贤达 阅读(1621) 评论(0) 编辑 收藏 举报--挂起业务存储过程 create procedure [dbo].[p_suspend_business] @Bfixednum varchar(40) as begin transaction declare @SNumber int declare @messageNumber int select @SNumber=SNumber from sendnumber where Bfixednum=@Bfixednum select @messageNumber = count(@Bfixednum) from [message] where Bfixednum = @Bfixednum and mDate between (select dateadd(dd,-day(getdate())+1,getdate())) and (select dateadd(dd,-day(getdate()),dateadd(m,1,getdate()))) --参数检查 if (@SNumber is null or @messageNumber = '') begin raiserror('错误!缺少参数 ,请检查!',16,1) rollback return end if (@messageNumber >= @SNumber) begin update dbo.Business set BState=0 where Bfixednum=@Bfixednum commit transaction end GO利用系统存储过程建立数据库链接EXEC sp_addlinkedserver 'lkTest', '', 'MSDASQL', NULL, NULL, 'DRIVER={SQL Server};SERVER=地址;UID=sa;PWD=密码;' go
--测式数据库语句运行的时间 declare @starttime as datetime; declare @endtime as datetime; set @starttime = getdate(); --运行的语句 select * from dbo.total where companyinfo like '%中南一路%' set @endtime = getdate();select @starttime as 开始时间,@endtime as 结束时间,datediff(MS,@starttime,@endtime)as 运行时间