代码改变世界

常用的数据库代码

  贤达  阅读(1681)  评论(0编辑  收藏  举报
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<pre class="brush:sql"><pre class="brush:sql">--挂起业务存储过程
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
 
 
 
</pre>
</pre>
<pre class="brush:sql">利用系统存储过程建立数据库链接</pre>
<pre class="brush:sql">EXEC sp_addlinkedserver
   'lkTest',
   '',
   'MSDASQL',
   NULL,
   NULL,
   'DRIVER={SQL Server};SERVER=地址;UID=sa;PWD=密码;'
 go
</pre>
1
2
3
4
5
6
7
8
9
<pre class="brush:sql">--测式数据库语句运行的时间
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 运行时间
 
</pre>

 

编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)
点击右上角即可分享
微信分享提示