while@k<=@number
begin
ifexists(select1fromsyscommentswhereid=object_id(@objectname)andnumber=@k)
begin
if@type=P
set@sql1=(casewhen@number>1thenALTERPROCEDURE+@objectname+;+rtrim(@k)+WITHENCRYPTIONAS
elseALTERPROCEDURE+@objectname+WITHENCRYPTIONAS
end)
if@type=TR
begin
declare@parent_objvarchar(255),@tr_parent_xtypevarchar(10)
select@parent_obj=parent_objfromsysobjectswhereid=object_id(@objectname)
select@tr_parent_xtype=xtypefromsysobjectswhereid=@parent_obj
if@tr_parent_xtype=V
begin
set@sql1=ALTERTRIGGER+@objectname+ON+OBJECT_NAME(@parentid)+WITHENCRYPTIONINSTERDOFINSERTASPRINT1
end
else
begin
set@sql1=ALTERTRIGGER+@objectname+ON+OBJECT_NAME(@parentid)+WITHENCRYPTIONFORINSERTASPRINT1
end
end
if@type=FNor@type=TFor@type=IF
set@sql1=(case@typewhenTFthen
ALTERFUNCTION+@objectname+(@achar(1))returns@btable(avarchar(10))withencryptionasbegininsert@bselect@areturnend
whenFNthen
ALTERFUNCTION+@objectname+(@achar(1))returnschar(1)withencryptionasbeginreturn@aend
whenIFthen
ALTERFUNCTION+@objectname+(@achar(1))returnstablewithencryptionasreturnselect@aasa
end)
if@tr_parent_xtype=V
begin
set@OrigSpText2=CREATETRIGGER+@objectname+ON+OBJECT_NAME(@parentid)+WITHENCRYPTIONINSTEADOFINSERTASPRINT1
end
else
begin
set@OrigSpText2=CREATETRIGGER+@objectname+ON+OBJECT_NAME(@parentid)+WITHENCRYPTIONFORINSERTASPRINT1
end