 
---- genera query para borras todas las tablas de log
select table_name nomtab,column_name nomcam,data_type tipdat,rtrim(COLUMN_NAME)+' '+RTRIM(DATA_TYPE)+
case when DATA_TYPE IN ('char','varchar') then '('+rtrim(cast(CHARACTER_MAXIMUM_LENGTH as CHAR))+')'
when DATA_TYPE ='numeric' then '('+RTRIM(cast(NUMERIC_PRECISION as CHAR))+','+rtrim(cast(NUMERIC_SCALE as CHAR))+')'
else '' end campo into #tablas_siav 
from "zapopan".INFORMATION_SCHEMA.COLUMNS where 
left(TABLE_NAME,4)='come' and column_name='key_log'
order by table_name,ORDINAL_POSITION      

select 'drop table '+RTRIM(nomtab)+';' from #tablas_siav

--drop table #tablas_siav
--select * from #tablas_siav

--- genera query para borrar indices 
select 'DROP INDEX '+rtrim(SO.Name)+'.'+rtrim(SI.name)
from sysobjects as SO 
    join sysindexes as SI on SO.Id = SI.id 
    join sysfilegroups as SFG on SI.GroupId = SFG.GroupId
where (left(so.name,4)='come' and CHARINDEX('_log',so.name)=0) and 
si.name <>'key_pri'
order by SO.Name , SI.name

--- genera query para borrar vistas,procedimientos,funciones y triggers
select case when TYPE='V' then 'drop view '+RTRIM(name)
when TYPE='P' then 'drop procedure dbo.'+rtrim(name)
when type='FN' then 'drop function dbo.'+rtrim(name)
when type='TR' then 'drop trigger dbo.'+rtrim(name)
end from sys.objects 
WHERE is_ms_shipped=0 AND TYPE IN ('V','P','FN','TR')
ORDER BY sys.objects.TYPE,name

drop table COMELOG;
DROP INDEX comeadu.LLA1_ADU
DROP INDEX comealm.LLA1_ALM
DROP INDEX comealm.LLA2_ALM
DROP INDEX comeban.LLA1_BAN
DROP INDEX comebul.LLA1_BUL
DROP INDEX comebul.LLA2_BUL
DROP INDEX comebul.LLA3_BUL
DROP INDEX comecad.LLA1_CAD
DROP INDEX comecam.LLA1_CAM
DROP INDEX comecap.LLA1_CAP
DROP INDEX comecap.LLA2_CAP
DROP INDEX comecct.LLA1_CCT
DROP INDEX comecer.LLA1_CER
DROP INDEX comecfd.LLA1_CFD
DROP INDEX comecin.LLA1_CIN
DROP INDEX comecon.LLA1_CON
DROP INDEX comecor.LLA1_COR
DROP INDEX comecpy.LLA1_CPY
DROP INDEX comecta.LLA1_CTA
DROP INDEX comedia.LLA1_DIA
DROP INDEX comedoc.LLA1_DOC
DROP INDEX comedoc.LLA2_DOC
DROP INDEX comedoc.LLA3_DOC
DROP INDEX comedoc.LLA4_DOC
DROP INDEX comedoc.LLA5_DOC
DROP INDEX comedoc.LLA6_DOC
DROP INDEX comedoc.LLA7_DOC
DROP INDEX comedpe.LLA1_DPE
DROP INDEX comedpe.LLA2_DPE
DROP INDEX comedpy.LLA1_DPY
DROP INDEX comedxm.LLA1_DXM
DROP INDEX comeemb.LLA1_EMB
DROP INDEX comeesc.LLA1_ESC
DROP INDEX comeesc.LLA2_ESC
DROP INDEX comeesp.LLA1_ESP
DROP INDEX comeesp.LLA2_ESP
DROP INDEX comeexp.LLA1_EXP
DROP INDEX comeexp.LLA2_EXP
DROP INDEX comefam.LLA1_FAM
DROP INDEX comefam.LLA2_FAM
DROP INDEX comefim.LLA1_FIM
DROP INDEX comefis.LLA1_FIS
DROP INDEX comefol.LLA1_FOL
DROP INDEX comefol.LLA2_FOL
DROP INDEX comefpe.LLA1_FPE
DROP INDEX comegam.LLA1_GAM
DROP INDEX comegau.LLA1_GAU
DROP INDEX comegau.LLA2_GAU
DROP INDEX comegau.LLA3_GAU
DROP INDEX comegco.LLA1_GCO
DROP INDEX comegpy.LLA1_GPY
DROP INDEX comegru.LLA1_GRU
DROP INDEX comegru.LLA2_GRU
DROP INDEX comeima.LLA1_IMA
DROP INDEX comeimp.LLA1_IMP
DROP INDEX comeisu.LLA1_ISU
DROP INDEX comeisu.LLA2_ISU
DROP INDEX comeisu.LLA3_ISU
DROP INDEX comekms.LLA1_KMS
DROP INDEX comekms.LLA2_KMS
DROP INDEX COMELOG.key_log
DROP INDEX COMELOG.LLA1_LOG
DROP INDEX comelot.LLA1_LOT
DROP INDEX comelpr.LLA1_LPR
DROP INDEX comemar.LLA1_MAR
DROP INDEX comemef.LLA1_MEF
DROP INDEX comemef.LLA2_MEF
DROP INDEX comemef.LLA3_MEF
DROP INDEX comemen.LLA1_MEN
DROP INDEX comemen.LLA2_MEN
DROP INDEX comemnt.LLA1_MNT
DROP INDEX comemnt.LLA2_MNT
DROP INDEX comemos.LLA1_MOS
DROP INDEX comemos.LLA2_MOS
DROP INDEX comemos.LLA3_MOS
DROP INDEX comemov.LLA1_MOV
DROP INDEX comemov.LLA2_MOV
DROP INDEX comemov.LLA5_MOV
DROP INDEX comemov.LLA6_MOV
DROP INDEX comemov.LLA7_MOV
DROP INDEX comempy.LLA1_MPY
DROP INDEX comemvt.LLA1_MVT
DROP INDEX comemvt.LLA2_MVT
DROP INDEX comenom.LLA1_NOM
DROP INDEX comenom.LLA2_NOM
DROP INDEX comenom.LLA3_NOM
DROP INDEX comenom.LLA4_NOM
DROP INDEX comenom.LLA5_NOM
DROP INDEX comenom.LLA6_NOM
DROP INDEX comepag.LLA1_PAG
DROP INDEX comepag.LLA2_PAG
DROP INDEX comepar.LLA1_PAR
DROP INDEX comepct.LLA1_PCT
DROP INDEX comeped.LLA1_PED
DROP INDEX comeped.LLA2_PED
DROP INDEX comeped.LLA3_PED
DROP INDEX comeper.LLA1_PER
DROP INDEX comepge.LLA1_PGE
DROP INDEX comepol.LLA1_POL
DROP INDEX comepol.LLA2_POL
DROP INDEX comepos.LLA1_POS
DROP INDEX comepos.LLA2_POS
DROP INDEX comepro.LLA1_PRO
DROP INDEX comepry.LLA1_PRY
DROP INDEX comepsd.LLA1_PSD
DROP INDEX comerec.LLA1_REC
DROP INDEX comerec.LLA2_REC
DROP INDEX comerec.LLa2_TPS
DROP INDEX comerec.LLA3_REC
DROP INDEX comerut.LLA1_RUT
DROP INDEX comerut.LLA2_RUT
DROP INDEX comerve.LLA1_RVE
DROP INDEX comerve.LLA2_RVE
DROP INDEX comerve.LLA3_RVE
DROP INDEX comerve.LLA4_RVE
DROP INDEX comerve.LLA5_RVE
DROP INDEX comesal.LLA1_SAL
DROP INDEX comesal.LLA2_SAL
DROP INDEX comeseg.LLA1_SEG
DROP INDEX comespy.LLA1_SPY
DROP INDEX cometaf.LLA1_TAF
DROP INDEX cometar.LLA1_TAR
DROP INDEX cometca.LLA1_TCA
DROP INDEX cometca.LLA2_TCA
DROP INDEX cometca.LLA3_TCA
DROP INDEX cometcd.LLA1_TCD
DROP INDEX cometco.LLA1_TCO
DROP INDEX cometda.LLA1_TDA
DROP INDEX cometdf.LLA1_TDF
DROP INDEX cometdi.LLA1_TDI
DROP INDEX cometdn.LLA1_TDN
DROP INDEX cometdo.LLA1_TDO
DROP INDEX cometdy.LLA1_TDY
DROP INDEX cometdy.LLA2_TDY
DROP INDEX cometel.LLA1_TEL
DROP INDEX cometel.LLA2_TEL
DROP INDEX cometel.LLA3_TEL
DROP INDEX cometfi.LLA1_TFI
DROP INDEX cometif.LLA1_TIF
DROP INDEX cometif.LLA2_TIF
DROP INDEX cometiu.LLA1_TIU
DROP INDEX cometps.LLA1_TPS
DROP INDEX cometps.LLA2_TPS
DROP INDEX cometpy.LLA1_TPY
DROP INDEX cometre.LLA1_TRE
DROP INDEX cometti.LLA1_TTI
DROP INDEX comeunn.LLA1_UNN
DROP INDEX comeunn.LLA2_UNN
DROP INDEX comeusu.LLA1_USU
DROP INDEX comevar.LLA1_VAR
DROP INDEX comeven.LLA1_VEN
DROP INDEX comevia.LLA1_VIA
DROP INDEX comevia.LLA2_VIA
DROP INDEX comevis.LLA1_VIS
DROP INDEX comevis.LLA2_VIS
DROP INDEX comevvi.LLA1_VVI
DROP INDEX comevvi.LLA2_VVI
DROP INDEX comevvi.LLA3_VVI
DROP INDEX comexmd.LLA1_XMD
DROP INDEX comexml.LLA1_XML

drop function dbo.F_CAL_COS_GEN
drop function dbo.F_CAL_EXI_GEN
drop function dbo.f_cal_gas_ini
drop function dbo.F_CAL_PDO_GEN
drop function dbo.F_CAL_SAL_DOC
drop function dbo.F_CAL_SAL_GEN
drop function dbo.F_CAL_SAL_NOM
drop function dbo.F_cal_sal_pro
drop function dbo.F_DES_PAL
drop function dbo.F_KEY_USU
drop function dbo.F_OBT_ATR_XML
drop function dbo.F_OBT_DAT_XML
drop function dbo.F_obt_ntv_dse_mov
drop procedure dbo.BAJ_DOC
drop procedure dbo.BLO_CLI
drop procedure dbo.CAL_APA_GEN
drop procedure dbo.CAL_COS_GEN
drop procedure dbo.CAL_COS_PED
drop procedure dbo.CAL_COS_PRO
drop procedure dbo.CAL_EST_DOC
drop procedure dbo.CAL_EXI_GEN
drop procedure dbo.CAL_EXI_TIF
drop procedure dbo.CAL_PDO_GEN
drop procedure dbo.CAL_PRE
drop procedure dbo.CAL_SAL_DOC
drop procedure dbo.CAL_SAL_GEN
drop procedure dbo.CAL_SAL_NOM
drop procedure dbo.CAM_CLA
drop procedure dbo.CAM_COD
drop procedure dbo.CAN_DOC
drop procedure dbo.CIE_PER
drop procedure dbo.CON_EXI_PED
drop procedure dbo.CON_EXI_SER
drop procedure dbo.CON_GEN_DOC
drop procedure dbo.CON_PDO_SUR
drop procedure dbo.GEN_AJU_INV
drop procedure dbo.GET_CON_DOC
drop procedure dbo.GET_FEC
drop procedure dbo.GET_PED
drop procedure dbo.GET_SER
drop procedure dbo.LOG_NOM
drop procedure dbo.P_aju_cxc_dis
drop procedure dbo.P_aju_sal_cxc_dis
drop procedure dbo.P_AJU_SAL_DOC
drop procedure dbo.P_apa_sta_rve
drop procedure dbo.p_cal_caj_cub
drop procedure dbo.P_cal_cor_rut
drop procedure dbo.P_CAL_ORD_POS
drop procedure dbo.P_CAL_PRE_ISU
drop procedure dbo.P_CAL_PRE_ISU_N
drop procedure dbo.P_CAL_PUN_REO
drop procedure dbo.P_cal_sal_pro
drop procedure dbo.P_cam_pre
drop procedure dbo.p_cam_ven
drop procedure dbo.P_CON_EXI
drop procedure dbo.P_CON_POS
drop procedure dbo.P_COT_EMB
drop procedure dbo.P_GEN_COS_ENT
drop procedure dbo.P_GEN_DOC_EXP
drop procedure dbo.P_GEN_FOL_TIV
drop procedure dbo.P_GEN_POS
drop procedure dbo.P_GET_CON_COD
drop procedure dbo.P_OBT_DAT_CFD
drop procedure dbo.P_OBT_XML
drop procedure dbo.P_ORD_ENT_POS
drop procedure dbo.P_PRE_CIE
drop procedure dbo.P_RECAL_ORD_POS
drop procedure dbo.PW_BAJ_MOV
drop procedure dbo.PW_CON_DOC
drop procedure dbo.PW_CON_NOM
drop procedure dbo.PW_EXI_PRO
drop procedure dbo.PW_INS_MOV
drop procedure dbo.PW_LIS_DOC
drop procedure dbo.PW_LIS_MOV
drop procedure dbo.PW_LIS_PRE
drop procedure dbo.PW_MAN_DOC
drop trigger dbo.BOR_DOC
drop trigger dbo.BOR_MOV
drop trigger dbo.BOR_NOM
drop trigger dbo.BOR_PAG
drop trigger dbo.INS_DOC
drop trigger dbo.INS_DOC_CAJ
drop trigger dbo.INS_DPE
drop trigger dbo.INS_MOV
drop trigger dbo.INS_PAG
drop trigger dbo.INS_PED
drop trigger dbo.INS_TDN
drop trigger dbo.INS_TDO
drop trigger dbo.MOD_DOC
drop trigger dbo.MOD_ISU
drop trigger dbo.MOD_MOV
drop trigger dbo.MOD_NOM
drop trigger dbo.MOD_PAG
drop trigger dbo.MOD_TDA
drop trigger dbo.T_ACT_ALM
drop trigger dbo.t_blo_cor_sep
drop trigger dbo.T_bor_rve
drop trigger dbo.T_cie_par_suc
drop trigger dbo.T_INS_BUL
drop trigger dbo.T_ins_doc_dis
drop trigger dbo.T_ins_rve
drop trigger dbo.T_INS_TCD
drop trigger dbo.T_log_ALM
drop trigger dbo.T_log_CAD
drop trigger dbo.T_log_CAM
drop trigger dbo.T_log_CAP
drop trigger dbo.T_log_CON
drop trigger dbo.T_log_COR
drop trigger dbo.T_log_DOC
drop trigger dbo.T_log_DPE
drop trigger dbo.T_log_ESC
drop trigger dbo.T_log_ESP
drop trigger dbo.T_log_EXP
drop trigger dbo.T_log_FAM
drop trigger dbo.T_log_FIM
drop trigger dbo.T_log_FIS
drop trigger dbo.T_log_FOL
drop trigger dbo.T_log_FPE
drop trigger dbo.T_log_GCO
drop trigger dbo.T_log_GRU
drop trigger dbo.T_log_IMP
drop trigger dbo.T_log_ISU
drop trigger dbo.T_log_KMS
drop trigger dbo.T_log_LOT
drop trigger dbo.T_log_LPR
drop trigger dbo.T_log_MEN
drop trigger dbo.T_log_MOS
drop trigger dbo.T_log_MOV
drop trigger dbo.T_log_NOM
drop trigger dbo.T_log_PAG
drop trigger dbo.T_log_PED
drop trigger dbo.T_log_PRO
drop trigger dbo.T_log_PSD
drop trigger dbo.T_log_RUT
drop trigger dbo.T_log_RVE
drop trigger dbo.T_log_SEG
drop trigger dbo.T_log_TAR
drop trigger dbo.T_log_TCA
drop trigger dbo.T_log_TDA
drop trigger dbo.T_log_TDF
drop trigger dbo.T_log_TDN
drop trigger dbo.T_log_TDO
drop trigger dbo.T_log_TEL
drop trigger dbo.T_log_TFI
drop trigger dbo.T_log_TIF
drop trigger dbo.T_log_TPS
drop trigger dbo.T_log_TTI
drop trigger dbo.T_log_USU
drop trigger dbo.T_log_VAR
drop trigger dbo.T_log_VEN
drop trigger dbo.T_MOD_PGE
drop trigger dbo.T_mod_rve
drop view VCOME0111
drop view VCOME0115
drop view VCOME0204
drop view VCOME1201
drop view VCOME1201_C
drop view VCOME1203
drop view VCOME1205
drop view VCOME1205_D
drop view VCOME1206
drop view VCOME1207
drop view VCOME1209
drop view VCOME2201
drop view VCOME2202
drop view VCOME2203
drop view VCOME2204
drop view VCOME3201
drop view VCOME3203
drop view VCOME3204
drop view VCOME3205
drop view VCOME3206
drop view VCOME3207
drop view vcome3208
drop view VCOME3210
drop view VCOME3211
drop view VCOME3212
drop view VCOME3214
drop view VCOME3216_P
drop view VCOME3216_S
drop view VCOME3217
drop view VCOME3219
drop view VCOME3220
drop view VCOME3225
drop view VCOME3226
drop view VCOME3227
drop view VCOME3229
drop view VCOME3230
drop view VCOME5201_D
drop view VCOME5201_G
drop view VCOME5203
drop view VCOME5206
drop view VCOME5207
drop view VCOME5213
drop view VCOME5216
drop view VCOME5217
drop view VCOME5307
drop view VCOME5309
drop view VCOME7201
drop view VCOME7202
drop view VCOME7203
drop view VCOME7204
drop view VCOMESAL
drop view VDIST1201
drop view VDIST1211
drop view vdist1216
drop view vdist1217
drop view vdist1220
drop view vdist1223
drop view vdist1224
drop view vdist2201
drop view vdist2202
drop view vdist2203
drop view vdist2204
drop view vdist2205
drop view vdist2207
drop view vdist2209
drop view VW_CAT_PRO
drop view VW_COMEISU

