

if not exists (select * from _tablas where tabla ='ter_cargoContacto')
begin
EXEC _ini_creartabla 'ter_cargoContacto', 1

 
end

if not exists(select * FROM INFORMATION_SCHEMA.COLUMNS  where Table_Name='ter_contacto' and column_name = 'id_cargoContacto' )
begin
alter table [ter_contacto] add [id_cargoContacto] int
end


if not exists (select * from _tablas where tabla='ter_cargoContacto')
begin
insert into [_tablas] (tabla,esMultiempresa,duplicar,eliminarIntermedias)
values
('ter_cargoContacto',1,0,0)
end



IF NOT EXISTS(SELECT *FROM [_columnas] WHERE[tabla]='ter_contacto'
      AND [columna]='id_cargoContacto'AND[mostrarEnGrilla]=1 AND [ordenGrilla]=1 AND [requerido]=0 AND [tipo]='int' AND [defecto] is null )
BEGIN
insert into [_columnas] ([tabla], [columna] ,[mostrarEnGrilla] ,[ordenGrilla] ,[requerido] ,[tipo] ,[defecto] ,[tamano] )
values ('ter_contacto','id_cargoContacto',1,1,1,'int', ' ', 5)
END




if not exists (select * from [_columnas] where [tabla] ='ter_cargoContacto' and [columna]='id')
begin
INSERT INTO [_columnas]
           ([tabla],[columna],[mostrarEnGrilla],[ordenGrilla],[requerido],[tipo],[defecto],[tamano])
     VALUES
			('ter_cargoContacto','id',1,1,1,'int',NULL,NULL)
end

if not exists (select * from [_columnas] where [tabla] ='ter_cargoContacto' and [columna]='uid')
begin
INSERT INTO [_columnas]
           ([tabla],[columna],[mostrarEnGrilla],[ordenGrilla],[requerido],[tipo],[defecto],[tamano])
     VALUES
			('ter_cargoContacto','uid',1,1,1,'varchar',NULL,500)
end

if not exists (select * from [_columnas] where [tabla] ='ter_cargoContacto' and [columna]='eid')
begin
INSERT INTO [_columnas]
           ([tabla],[columna],[mostrarEnGrilla],[ordenGrilla],[requerido],[tipo],[defecto],[tamano])
     VALUES
			('ter_cargoContacto','eid',1,1,1,'varchar',NULL,50)
end

if not exists (select * from [_columnas] where [tabla] ='ter_cargoContacto' and [columna]='id_usuario_Modifico')
begin
INSERT INTO [_columnas]
           ([tabla],[columna],[mostrarEnGrilla],[ordenGrilla],[requerido],[tipo],[defecto],[tamano])
     VALUES
			('ter_cargoContacto','id_usuario_Modifico',1,1,1,'int',0,NULL)
end

if not exists (select * from [_columnas] where [tabla] ='ter_cargoContacto' and [columna]='id_usuario_Creo')
begin
INSERT INTO [_columnas]
           ([tabla],[columna],[mostrarEnGrilla],[ordenGrilla],[requerido],[tipo],[defecto],[tamano])
     VALUES
			('ter_cargoContacto','id_usuario_Creo',1,1,1,'int',0,NULL)
end

if not exists (select * from [_columnas] where [tabla] ='ter_cargoContacto' and [columna]='fechaModificacion')
begin
INSERT INTO [_columnas]
           ([tabla],[columna],[mostrarEnGrilla],[ordenGrilla],[requerido],[tipo],[defecto],[tamano])
     VALUES
			('ter_cargoContacto','fechaModificacion',1,1,1,'datetime','(getdate())',NULL)
end

if not exists (select * from [_columnas] where [tabla] ='ter_cargoContacto' and [columna]='fechaCreacion')
begin
INSERT INTO [_columnas]
           ([tabla],[columna],[mostrarEnGrilla],[ordenGrilla],[requerido],[tipo],[defecto],[tamano])
     VALUES
			('ter_cargoContacto','fechaCreacion',1,1,1,'smalltime','(getdate())',NULL)
end

if not exists (select * from [_columnas] where [tabla] ='ter_cargoContacto' and [columna]='active')
begin
INSERT INTO [_columnas]
           ([tabla],[columna],[mostrarEnGrilla],[ordenGrilla],[requerido],[tipo],[defecto],[tamano])
     VALUES
			('ter_cargoContacto','active',1,1,1,'bit',1,NULL)
end

if not exists (select * from [_columnas] where [tabla] ='ter_cargoContacto' and [columna]='cargoContacto')
begin
INSERT INTO [_columnas]
           ([tabla],[columna],[mostrarEnGrilla],[ordenGrilla],[requerido],[tipo],[defecto],[tamano])
     VALUES
			('ter_cargoContacto','cargoContacto',1,1,0,'varchar',NULL,300)
end

if not exists (select * from [_columnas] where [tabla] ='ter_cargoContacto' and [columna]='cargoContacto_codigo')
begin
INSERT INTO [_columnas]
           ([tabla],[columna],[mostrarEnGrilla],[ordenGrilla],[requerido],[tipo],[defecto],[tamano])
     VALUES
			('ter_cargoContacto','cargoContacto_codigo',1,1,0,'varchar',NULL,100)
end
----

