IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_gen_dptcreate_trg]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_gen_dptcreate_trg]
GO
create procedure [dbo].[mps_gen_dptcreate_trg](
@cmpid int
)
as
begin
set nocount on
declare @tbname varchar(50)
declare @dbname varchar(50)
declare @fkey   varchar(50) 
exec sys_sql_getTableNamePk @cmpid,'dpt',@cmpid,0,@tbname output,@fkey output ,@dbname output 
declare @sql nvarchar(MAX) 

if (dbo.mps_sys_checkkeywords('dpt.aftercreate_trg',@cmpid,0,'','')<>0) 
begin
set @sql = 'drop TRIGGER '+@tbname+'_insert_trg' 
if (dbo.checktrigger(@tbname+'_insert_trg')=0) execute(@sql)  
return 
end


set @sql = N'
-- 生成时间:'+convert(varchar(20),getdate(),120)+N' by ebs-core  
'
if (dbo.checktrigger(@tbname+'_insert_trg')=0) set @sql=@sql+'alter ' else set @sql=@sql+'create '
set @sql = @sql+' TRIGGER '+@tbname+'_insert_trg on '+ @tbname +' 
for insert 
as  
begin  
 '
 
set @sql=@sql+N'
 ---- 以下是开发人员写的insert·触发器事件 --------------
 '
 + dbo.mps_sys_getusercode('dpt.aftercreate_trg',@cmpid,0) +N'
 ---- 以上是开发人员写的insert·触发器事件 --------------
 
 ' 
 
set @sql = @sql +N'
end
'
exec myprint @sql 
execute(@sql) 
set nocount off 
end