/********************************************************************************************/
/* Remove all existing refrences to SQLTrace XPs                                            */
/********************************************************************************************/

use master
go

if exists (select * from master.dbo.sysobjects where name = 'xp_sqltrace')
  EXEC sp_dropextendedproc 'xp_sqltrace'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_addnewqueue')
  EXEC sp_dropextendedproc 'xp_trace_addnewqueue'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_destroyqueue')
  EXEC sp_dropextendedproc 'xp_trace_destroyqueue'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_enumqueuehandles')
  EXEC sp_dropextendedproc 'xp_trace_enumqueuehandles'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_enumqueuedefname')
  EXEC sp_dropextendedproc 'xp_trace_enumqueuedefname'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_seteventclassrequired')
  EXEC sp_dropextendedproc 'xp_trace_seteventclassrequired'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_geteventnames')
  EXEC sp_dropextendedproc 'xp_trace_geteventnames'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_opentracefile')
  EXEC sp_dropextendedproc 'xp_trace_opentracefile'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_savequeuedefinition')
  EXEC sp_dropextendedproc 'xp_trace_savequeuedefinition'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_loadqueuedefinition')
  EXEC sp_dropextendedproc 'xp_trace_loadqueuedefinition'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_deletequeuedefinition')
  EXEC sp_dropextendedproc 'xp_trace_deletequeuedefinition'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_setqueueautostart')
  EXEC sp_dropextendedproc 'xp_trace_setqueueautostart'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_setappfilter')
  EXEC sp_dropextendedproc 'xp_trace_setappfilter'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_getappfilter')
  EXEC sp_dropextendedproc 'xp_trace_getappfilter'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_sethostfilter')
  EXEC sp_dropextendedproc 'xp_trace_sethostfilter'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_gethostfilter')
  EXEC sp_dropextendedproc 'xp_trace_gethostfilter'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_setuserfilter')
  EXEC sp_dropextendedproc 'xp_trace_setuserfilter'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_getuserfilter')
  EXEC sp_dropextendedproc 'xp_trace_getuserfilter'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_seteventfilter')
  EXEC sp_dropextendedproc 'xp_trace_seteventfilter'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_geteventfilter')
  EXEC sp_dropextendedproc 'xp_trace_geteventfilter'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_setcpufilter')
  EXEC sp_dropextendedproc 'xp_trace_setcpufilter'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_getcpufilter')
  EXEC sp_dropextendedproc 'xp_trace_getcpufilter'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_setdbidfilter')
  EXEC sp_dropextendedproc 'xp_trace_setdbidfilter'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_getdbidfilter')
  EXEC sp_dropextendedproc 'xp_trace_getdbidfilter'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_setdurationfilter')
  EXEC sp_dropextendedproc 'xp_trace_setdurationfilter'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_getdurationfilter')
  EXEC sp_dropextendedproc 'xp_trace_getdurationfilter'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_sethpidfilter')
  EXEC sp_dropextendedproc 'xp_trace_sethpidfilter'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_gethpidfilter')
  EXEC sp_dropextendedproc 'xp_trace_gethpidfilter'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_setindidfilter')
  EXEC sp_dropextendedproc 'xp_trace_setindidfilter'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_getindidfilter')
  EXEC sp_dropextendedproc 'xp_trace_getindidfilter'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_setspidfilter')
  EXEC sp_dropextendedproc 'xp_trace_setspidfilter'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_getspidfilter')
  EXEC sp_dropextendedproc 'xp_trace_getspidfilter'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_setntdmfilter')
  EXEC sp_dropextendedproc 'xp_trace_setntdmfilter'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_getntdmfilter')
  EXEC sp_dropextendedproc 'xp_trace_getntdmfilter'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_setntnmfilter')
  EXEC sp_dropextendedproc 'xp_trace_setntnmfilter'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_getntnmfilter')
  EXEC sp_dropextendedproc 'xp_trace_getntnmfilter'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_setobjidfilter')
  EXEC sp_dropextendedproc 'xp_trace_setobjidfilter'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_getobjidfilter')
  EXEC sp_dropextendedproc 'xp_trace_getobjidfilter'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_setreadfilter')
  EXEC sp_dropextendedproc 'xp_trace_setreadfilter'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_getreadfilter')
  EXEC sp_dropextendedproc 'xp_trace_getreadfilter'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_setseverityfilter')
  EXEC sp_dropextendedproc 'xp_trace_setseverityfilter'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_getseverityfilter')
  EXEC sp_dropextendedproc 'xp_trace_getseverityfilter'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_setconnectionidfilter')
  EXEC sp_dropextendedproc 'xp_trace_setconnectionidfilter'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_getconnectionidfilter')
  EXEC sp_dropextendedproc 'xp_trace_getconnectionidfilter'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_setwritefilter')
  EXEC sp_dropextendedproc 'xp_trace_setwritefilter'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_getwritefilter')
  EXEC sp_dropextendedproc 'xp_trace_getwritefilter'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_pausequeue')
  EXEC sp_dropextendedproc 'xp_trace_pausequeue'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_restartqueue')
  EXEC sp_dropextendedproc 'xp_trace_restartqueue'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_getqueueautostart')
  EXEC sp_dropextendedproc 'xp_trace_getqueueautostart'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_eventclassrequired')
  EXEC sp_dropextendedproc 'xp_trace_eventclassrequired'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_getqueueproperties')
  EXEC sp_dropextendedproc 'xp_trace_getqueueproperties'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_getevents')
  EXEC sp_dropextendedproc 'xp_trace_getevents'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_setqueryhistory')
  EXEC sp_dropextendedproc 'xp_trace_setqueryhistory'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_flushqueryhistory')
  EXEC sp_dropextendedproc 'xp_trace_flushqueryhistory'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_load_dummy_handlers')
  EXEC sp_dropextendedproc 'xp_load_dummy_handlers'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_unload_dummy_handlers')
  EXEC sp_dropextendedproc 'xp_unload_dummy_handlers'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_param_dump')
  EXEC sp_dropextendedproc 'xp_param_dump'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_settextfilter')
  EXEC sp_dropextendedproc 'xp_trace_settextfilter'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_gettextfilter')
  EXEC sp_dropextendedproc 'xp_trace_gettextfilter'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_generate_event')
  EXEC sp_dropextendedproc 'xp_trace_generate_event'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_setqueuedestination')
  EXEC sp_dropextendedproc 'xp_trace_setqueuedestination'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_getqueuedestination')
  EXEC sp_dropextendedproc 'xp_trace_getqueuedestination'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_startconsumer')
  EXEC sp_dropextendedproc 'xp_trace_startconsumer'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_setqueuecreateinfo')
  EXEC sp_dropextendedproc 'xp_trace_setqueuecreateinfo'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_getqueuecreateinfo')
  EXEC sp_dropextendedproc 'xp_trace_getqueuecreateinfo'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_setserverfilter')
  EXEC sp_dropextendedproc 'xp_trace_setserverfilter'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_getserverfilter')
  EXEC sp_dropextendedproc 'xp_trace_getserverfilter'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_setsysobjectsfilter')
  EXEC sp_dropextendedproc 'xp_trace_setsysobjectsfilter'
go

if exists (select * from master.dbo.sysobjects where name = 'xp_trace_getsysobjectsfilter')
  EXEC sp_dropextendedproc 'xp_trace_getsysobjectsfilter'
go
/********************************************************************************************/
/* Add all the SQLTrace XPs                                                                 */
/********************************************************************************************/

sp_MS_upd_sysobj_category 1
go

print 'Creating extended stored procedure xp_sqltrace'
go
sp_addextendedproc 'xp_sqltrace','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_addnewqueue'
go
sp_addextendedproc 'xp_trace_addnewqueue','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_destroyqueue'
go
sp_addextendedproc 'xp_trace_destroyqueue','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_enumqueuehandles'
go
sp_addextendedproc 'xp_trace_enumqueuehandles','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_enumqueuedefname'
go
sp_addextendedproc 'xp_trace_enumqueuedefname','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_seteventclassrequired'
go
sp_addextendedproc 'xp_trace_seteventclassrequired','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_geteventnames'
go
sp_addextendedproc 'xp_trace_geteventnames','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_opentracefile'
go
sp_addextendedproc 'xp_trace_opentracefile','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_savequeuedefinition'
go
sp_addextendedproc 'xp_trace_savequeuedefinition','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_loadqueuedefinition'
go
sp_addextendedproc 'xp_trace_loadqueuedefinition','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_deletequeuedefinition'
go
sp_addextendedproc 'xp_trace_deletequeuedefinition','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_setqueueautostart'
go
sp_addextendedproc 'xp_trace_setqueueautostart','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_setappfilter'
go
sp_addextendedproc 'xp_trace_setappfilter','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_getappfilter'
go
sp_addextendedproc 'xp_trace_getappfilter','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_sethostfilter'
go
sp_addextendedproc 'xp_trace_sethostfilter','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_gethostfilter'
go
sp_addextendedproc 'xp_trace_gethostfilter','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_setuserfilter'
go
sp_addextendedproc 'xp_trace_setuserfilter','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_getuserfilter'
go
sp_addextendedproc 'xp_trace_getuserfilter','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_seteventfilter'
go
sp_addextendedproc 'xp_trace_seteventfilter','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_geteventfilter'
go
sp_addextendedproc 'xp_trace_geteventfilter','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_setcpufilter'
go
sp_addextendedproc 'xp_trace_setcpufilter','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_getcpufilter'
go
sp_addextendedproc 'xp_trace_getcpufilter','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_setdbidfilter'
go
sp_addextendedproc 'xp_trace_setdbidfilter','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_getdbidfilter'
go
sp_addextendedproc 'xp_trace_getdbidfilter','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_setdurationfilter'
go
sp_addextendedproc 'xp_trace_setdurationfilter','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_getdurationfilter'
go
sp_addextendedproc 'xp_trace_getdurationfilter','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_sethpidfilter'
go
sp_addextendedproc 'xp_trace_sethpidfilter','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_gethpidfilter'
go
sp_addextendedproc 'xp_trace_gethpidfilter','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_setindidfilter'
go
sp_addextendedproc 'xp_trace_setindidfilter','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_getindidfilter'
go
sp_addextendedproc 'xp_trace_getindidfilter','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_setspidfilter'
go
sp_addextendedproc 'xp_trace_setspidfilter','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_getspidfilter'
go
sp_addextendedproc 'xp_trace_getspidfilter','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_setntdmfilter'
go
sp_addextendedproc 'xp_trace_setntdmfilter','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_getntdmfilter'
go
sp_addextendedproc 'xp_trace_getntdmfilter','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_setntnmfilter'
go
sp_addextendedproc 'xp_trace_setntnmfilter','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_getntnmfilter'
go
sp_addextendedproc 'xp_trace_getntnmfilter','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_setobjidfilter'
go
sp_addextendedproc 'xp_trace_setobjidfilter','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_getobjidfilter'
go
sp_addextendedproc 'xp_trace_getobjidfilter','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_setreadfilter'
go
sp_addextendedproc 'xp_trace_setreadfilter','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_getreadfilter'
go
sp_addextendedproc 'xp_trace_getreadfilter','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_setseverityfilter'
go
sp_addextendedproc 'xp_trace_setseverityfilter','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_getseverityfilter'
go
sp_addextendedproc 'xp_trace_getseverityfilter','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_setconnectionidfilter'
go
sp_addextendedproc 'xp_trace_setconnectionidfilter','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_getconnectionidfilter'
go
sp_addextendedproc 'xp_trace_getconnectionidfilter','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_setwritefilter'
go
sp_addextendedproc 'xp_trace_setwritefilter','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_getwritefilter'
go
sp_addextendedproc 'xp_trace_getwritefilter','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_pausequeue'
go
sp_addextendedproc 'xp_trace_pausequeue','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_restartqueue'
go
sp_addextendedproc 'xp_trace_restartqueue','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_getqueueautostart'
go
sp_addextendedproc 'xp_trace_getqueueautostart','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_eventclassrequired'
go
sp_addextendedproc 'xp_trace_eventclassrequired','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_getqueueproperties'
go
sp_addextendedproc 'xp_trace_getqueueproperties','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_getevents'
go
sp_addextendedproc 'xp_trace_getevents','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_setqueryhistory'
go
sp_addextendedproc 'xp_trace_setqueryhistory','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_flushqueryhistory'
go
sp_addextendedproc 'xp_trace_flushqueryhistory','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_settextfilter'
go
sp_addextendedproc 'xp_trace_settextfilter','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_gettextfilter'
go
sp_addextendedproc 'xp_trace_gettextfilter','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_generate_event'
go
sp_addextendedproc 'xp_trace_generate_event','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_setqueuedestination'
go
sp_addextendedproc 'xp_trace_setqueuedestination','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_getqueuedestination'
go
sp_addextendedproc 'xp_trace_getqueuedestination','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_startconsumer'
go
sp_addextendedproc 'xp_trace_startconsumer','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_setqueuecreateinfo'
go
sp_addextendedproc 'xp_trace_setqueuecreateinfo','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_getqueuecreateinfo'
go
sp_addextendedproc 'xp_trace_getqueuecreateinfo','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_setserverfilter'
go
sp_addextendedproc 'xp_trace_setserverfilter','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_getserverfilter'
go
sp_addextendedproc 'xp_trace_getserverfilter','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_setsysobjectsfilter'
go
sp_addextendedproc 'xp_trace_setsysobjectsfilter','SQLTrace.dll'
go

print 'Creating extended stored procedure xp_trace_getsysobjectsfilter'
go
sp_addextendedproc 'xp_trace_getsysobjectsfilter','SQLTrace.dll'
go

sp_MS_upd_sysobj_category 2
go
/************************************************************************************/
/*print 'Creating extended stored procedure xp_load_dummy_handlers'																*/
/*go																				*/
/*sp_addextendedproc 'xp_load_dummy_handlers','SQLTrace.dll'						*/
/*go																				*/

/*print 'Creating extended stored procedure xp_unload_dummy_handlers'																*/
/*go																				*/
/*sp_addextendedproc 'xp_unload_dummy_handlers','SQLTrace.dll'						*/
/*go																				*/

/*print 'Creating extended stored procedure xp_param_dump'																*/
/*go																				*/
/*sp_addextendedproc 'xp_param_dump','SQLTrace.dll'									*/
/*go																				*/
/************************************************************************************/
