常用SQL语句

raiserror('该用户授权无效', 16, 1,1)

 declare 定义

 --启动事务    
 declare @tran_point int      
 set @tran_point=@@trancount      
       
 if @tran_point=0      
  begin tran tran_hystatus      
 else      
   save tran tran_hystatus

 IF @@ERROR<>0 
   BEGIN      
     SET @return=1   
     set @returnstr='数据保存失败!'    
     GOTO err_lab      
   END  

 --事务处理      
 if @tran_point=0      
   commit tran tran_hystatus     
   set @returnstr='数据保存成功!'  
   goto return_lab      
       
 err_lab:           
   rollback tran tran_hystatus      
       
 return_lab:      
   return @return

if @@rowcount = 0

truncate table s_groupLicencs 清空表
通常情况,SQLServer2000正在使用的数据库(有数据库连接),是不能删除或被恢复的,可以将数据库设置为单用户模式,即可删除:
ALTER DATABASE IpaddrDB SET SINGLE_USER with ROLLBACK IMMEDIATE
DROP DATABASE IpaddrDB

 统计当前数据库连接数

select count(*) from master..sysprocesses where dbid=db_id('hbsdb')

USE master
EXEC sp_who  --所有连接

原文地址:https://www.cnblogs.com/jieke/p/2859552.html