IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_sys_checktrigger]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_sys_checktrigger]
GO
create procedure [dbo].[mps_sys_checktrigger](
@dboDotTable nvarchar(100),
@istrueOrFalse int output
) 
as
begin

declare @dboDotTableCopy nvarchar(100) = '',
@dbName nvarchar(100) = '',
@tableName nvarchar(100) = '',
@idxdbo int = -1,
@idx int = -1,
@runnable nvarchar(max)

set @istrueOrFalse = 2
set @dboDotTableCopy = lower(@dboDotTable)
 
if(CHARINDEX('.dbo.',@dboDotTableCopy)=1)
set @dboDotTableCopy = REPLACE(@dboDotTableCopy,'.dbo.','')
else if(CHARINDEX('dbo.',@dboDotTableCopy)=1)
set @dboDotTableCopy = REPLACE(@dboDotTableCopy,'dbo.','')
--else if(CHARINDEX('dbo',@dboDotTableCopy)=1 )
--set @dboDotTableCopy = REPLACE(@dboDotTableCopy,'dbo','')

--[.dbo.tablename  dbo.tablename  .tablename],没指定库
if(CHARINDEX('dbo',@dboDotTableCopy)=0 )
begin

set @tableName = @dboDotTableCopy

set @runnable = N'IF EXISTS(SELECT  * FROM dbo.SysObjects WHERE ID = object_id(N''['+@tableName+']'') AND (OBJECTPROPERTY(ID, ''IsTrigger'') = 1)) '+char(10) +
N'set@trueOrFalse =0 '+char(10) +
N'else '+char(10)+ 
N'set@trueOrFalse =1'

exec sp_executesql  @stmt = @runnable , 
@params = N'@trueOrFalse AS INT OUTPUT', 
@trueOrFalse = @istrueOrFalse output

end
--dbname.dbo.tablename 有库有表
else 
begin

set @idx = CHARINDEX('dbo',@dboDotTableCopy)
if(@idx > 0)
begin
set @dbName = lower(SUBSTRING(@dboDotTable,0,@idx-1))
set @tableName = lower(SUBSTRING(@dboDotTable,@idx+4,LEN(@dboDotTable)))

if exists(select 1 From master.dbo.sysdatabases where name= @dbName)
begin

set @runnable = N'use '+@dbName+N'; IF EXISTS(SELECT  * FROM dbo.SysObjects WHERE ID = object_id(N''['+@tableName+']'') AND (OBJECTPROPERTY(ID, ''IsTrigger'') = 1 )) '+char(10) +
N'set@trueOrFalse =0 '+char(10) +
N'else '+char(10)+ 
N'set@trueOrFalse =1'

exec sp_executesql  @stmt = @runnable , 
@params = N'@trueOrFalse AS INT OUTPUT', 
@trueOrFalse = @istrueOrFalse output
end
else
begin
set @istrueOrFalse = 1
end
end

end

end