Skip to content

조회 수 18170 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
SQL Agent에 등록되어 있는 작업이 현재 실행중인지를 확인하는 프로시저입니다.
 
간단할꺼라 생각했는데, 쉽게 확인할 수 있는 사항이 아니었네요~
시스템 테이블과 저장 프로시저들을 참고하여 한 번 만들어봤습니다.
SQL 2000에서도 제대로 돌아가기 위해 결과테이블을 테이블 변수 대신 임시테이블로 정의하였습니다.
SQL 2005에서는 테이블 변수에다가 execute 결과를 저장할 수가 있지만, SQL 2000에서는 안되어서요~^^
참고하시기 바랍니다.
 
 

CREATE PROC USP_CHECK_JOB_STATUS

             @job_name sysname AS

SET NOCOUNT ON

 

DECLARE @is_sysadmin INT 

DECLARE @job_owner   sysname 

DECLARE @job_id uniqueidentifier

 

IF OBJECT_ID('TEMPDB..#job_execution_state') IS NOT NULL

DROP TABLE #job_execution_state

 

CREATE TABLE #job_execution_state

                           (

                                        job_id                UNIQUEIDENTIFIER NOT NULL, 

            last_run_date         INT              NOT NULL, 

            last_run_time         INT              NOT NULL, 

            next_run_date         INT              NOT NULL, 

            next_run_time         INT              NOT NULL, 

            next_run_schedule_id  INT              NOT NULL, 

            requested_to_run      INT              NOT NULL, -- BOOL 

            request_source        INT              NOT NULL, 

            request_source_id     sysname          COLLATE database_default NULL, 

            running               INT              NOT NULL, -- BOOL 

            current_step          INT              NOT NULL, 

            current_retry_attempt INT              NOT NULL, 

            job_state             INT              NOT NULL) 

 

SELECT @is_sysadmin = ISNULL(IS_SRVROLEMEMBER(N'sysadmin'), 0) 

SELECT @job_owner = SUSER_SNAME()

SELECT @job_id = job_id FROM msdb.dbo.sysjobs where name = @job_name

 

IF @job_id IS NOT NULL

             BEGIN

                           INSERT INTO #job_execution_state

                           EXEC master.dbo.xp_sqlagent_enum_jobs @is_sysadmin, @job_owner, @job_id

 

                           IF EXISTS (SELECT * FROM #job_execution_state)

                                        SELECT @job_name AS Name, running AS Status, CASE WHEN running = 1 THEN '실행중' ELSE '실행중이지 않음' END AS Comments

                                        FROM #job_execution_state

                           ELSE

                                        SELECT @job_name as Name, -1 as Status, '해당 작업이 없습니다.' AS Comments

             END

ELSE

             SELECT @job_name as Name, -1 as Status, '해당 작업이 없습니다.' AS Comments

 

SET NOCOUNT OFF

GO

 

 
 

USP_CHECK_JOB_STATUS 'TEST'

/*

Name     Status      Comments

-------- ----------- --------

TEST     1           실행중

*/

 

USP_CHECK_JOB_STATUS 'TEST'

/*

Name     Status      Comments

-------- ----------- --------

TEST     0           실행중이지 않음

*/

 

USP_CHECK_JOB_STATUS 'TEST1'

/*

Name     Status      Comments

-------- ----------- --------

TEST1     -1         해당 작업이 없습니다.

*/


  1. DB 서버에 특정 IP 접근 차단 방법

    Date2010.02.21 Byl2zeo Views22212
    Read More
  2. DBCC SHRINKFILE 트랜잭션 로그파일 축소

    Date2010.05.29 Byl2zeo Views21798
    Read More
  3. Fatal error: Call to undefined function: mssql_connect()

    Date2010.06.03 ByADMINPLAY Views23013
    Read More
  4. Firehose 모드에서는 트랜젝션을 시작할수 없습니다

    Date2009.04.13 ByADMINPLAY Views7493
    Read More
  5. MicroSoft SQL Server 2008 1433 port 원격(외부)접속 허용하기

    Date2014.09.20 ByADMINPLAY Views4971
    Read More
  6. Ms-Sql 백업 format옵션

    Date2009.11.26 ByADMINPLAY Views9850
    Read More
  7. MS-SQL 클라이언트 설치 방법

    Date2009.11.26 ByADMINPLAY Views16254
    Read More
  8. MSSQL 2005 접속 클라이언트(mssql server management Studio ...

    Date2009.11.26 ByADMINPLAY Views16335
    Read More
  9. MSSQL 버전별 최대 용량 비교표

    Date2010.02.24 Byl2zeo Views23864
    Read More
  10. MSSQL 접속 방법

    Date2009.11.26 ByADMINPLAY Views9163
    Read More
  11. MSSQL 클러스터

    Date2009.11.19 ByADMINPLAY Views9663
    Read More
  12. MSSQL 트랜잭션로그삭제

    Date2009.05.15 ByADMINPLAY Views11520
    Read More
  13. MSSQL 파일사이즈 줄이기

    Date2009.11.10 ByADMINPLAY Views7519
    Read More
  14. mssql2005 원격접속 허용 - 노출 영역 구성

    Date2009.06.04 ByADMINPLAY Views10424
    Read More
  15. MsSQL에서 소유자(mssql2000 => mssql2005으로 복원)

    Date2009.11.26 ByADMINPLAY Views9323
    Read More
  16. mysql 대량 쿼리 보내기

    Date2008.12.14 ByADMIN Views8786
    Read More
  17. php에서 mssql 연동방법(총정리)

    Date2009.04.13 ByADMINPLAY Views16783
    Read More
  18. sa계정 패스워드변경하기

    Date2009.05.07 ByADMINPLAY Views10897
    Read More
  19. SET LOCK_TIMEOUT

    Date2012.01.16 ByADMINPLAY Views14549
    Read More
  20. SQL Agent 작업 실행 상태 확인하기

    Date2010.02.23 Byl2zeo Views18170
    Read More
Board Pagination Prev 1 2 Next
/ 2

Copyright ADMINPLAY corp. All rights reserved.

abcXYZ, 세종대왕,1234

abcXYZ, 세종대왕,1234