SQL Server 의 확장 저장 프로시저

4145 단어
--1.       
execute master..xp_getnetname 

--             
select SERVERPROPERTY('MachineName') 

--            
select @@SERVERNAME  


--2.        
if exists(select 1 from sys.tables where name = 'errorLog')
begin
	drop table errorLog
end

create table errorLog
(
LogDate datetime,
ProcessInfo nvarchar(20),
Text nvarchar(max)
)

insert into errorlog
exec master.sys.sp_readerrorlog

select *
from errorLog


--      xp_ReadErrorLog
--  sys.xp_ReadErrorLog   master.dbo.xp_ReadErrorLog
select *
from sys.all_sql_modules
where definition like '%sys.xp_ReadErrorLog%'


/*===================================================
                ,  6       ,
               ,          :6~99 。

     @p1,                ,
      :
		0:   ,               
		1:        1           
		2:        2           
		3:        3           
		4:        4           
		5:        5           
		6:        6           
=====================================================*/
exec master.dbo.xp_ReadErrorLog @p1 = 1



--3.           OLEDB    
if exists(select 1 from sys.tables where name = 'oledbProvider')
begin
	drop table oledbProvider
end

create table oledbProvider
(
ProviderName nvarchar(50),
ProcessInfo nvarchar(100),
Text nvarchar(100)
)

insert into oledbProvider
execute master..xp_enum_oledb_providers 

select *
from oledbProvider



--4.                
if exists(select 1 from sys.tables where name = 'fixeddrivesFreeSpace')
begin
	drop table fixeddrivesFreeSpace
end

create table fixeddrivesFreeSpace
(
drive nvarchar(10),   --  ,  ':\'
freeSpace bigint      -- MB        
)

insert into fixeddrivesFreeSpace
execute master..xp_fixeddrives 

select drive '  ',   
       freeSpace * 1.0 / 1024  '    (GB)'
from fixeddrivesFreeSpace



--5.                  
if exists(select 1 from sys.tables where name = 'availablemediaFreeSpace')
begin
	drop table availablemediaFreeSpace
end

create table availablemediaFreeSpace
(
name nvarchar(10),   --  , ':\'
lowFree bigint,      --       32    
highFree int,        --       32    
mediaType tinyint    -- MB        
)

insert into availablemediaFreeSpace
exec master.dbo.xp_availablemedia

/*=============================================
    :

 32  :  lowfree  (65536 * 65536)+  lowfree 
 32  :highfree * (65536 * 65536) 

     =  32   +  32  
===============================================*/
select name '  ',   
       lowfree,
       highfree,
       
       case when sign(lowfree) = 1  --    1
                 then lowfree + highfree * (1.0 * 65536 * 65536)
            else lowfree + (1.0 * 65536 * 65536) + highfree * (1.0 * 65536 * 65536) 
       end / 1024 /1024 / 1024 '    (GB)',
       
       case when mediaType = 1
                 then '  '
            when mediaType = 2
                 then '  '
            when mediaType = 8
                 then 'CD-ROM'
       end '      '
from availablemediaFreeSpace



--6.        windows    
execute master..xp_enumgroups 


--7.             
/*========================================
  1:   
  2:    
  3:      
==========================================*/
--  c           
execute master..xp_dirtree 'c:',1,1 


--  c        ,     
execute master..xp_dirtree 'c:',1  


--  c          
execute master..xp_dirtree 'c:',0,1


--           
EXEC master.dbo.xp_subdirs 'C:\'



--8.      
if exists(select 1 from sys.tables where name = 'fileExists')
begin
	drop table fileExists
end

create table fileExists
(
fileExists tinyint,             --      
IsDirectory tinyint,            --     
parentDirectoryExists tinyint   --       
)

insert into fileExists
execute master..xp_fileexist 'c:\c.txt' 

select *
from fileExists

 서비스 시작 여부 조회
--  SQL Server     :MSSQLSERVER
select @@servicename


--         ,  CurrentServiceState :Running.
--         
EXEC master.dbo.xp_servicecontrol 
	N'QUERYSTATE',        --    
	N'MSSQLSERVER'        --     SQL Server     
	

좋은 웹페이지 즐겨찾기