


IF NOT EXISTS(SELECT * FROM [_tablas] WHERE [tabla]='ter_sector')
BEGIN
INSERT INTO [_tablas]
([tabla] ,[esMultiempresa] ,[duplicar],[eliminarIntermedias])
 VALUES
 ('ter_sector' ,1 ,0 ,0)
END



IF NOT EXISTS(SELECT * FROM [_columnas] WHERE [tabla]='ter_sector'
AND [columna]='sector' AND [mostrarEnGrilla]=1 AND [ordenGrilla]=1 AND [requerido]=1 AND [tipo]='varchar' AND [defecto]=0)
BEGIN
INSERT INTO [_columnas]
([tabla] ,[columna] ,[mostrarEnGrilla],[ordenGrilla],[requerido] ,[tipo],[defecto],[tamano])
 VALUES
 ('ter_sector' ,'sector',1 ,1 ,1 ,'varchar' ,0 ,300)
END


IF NOT EXISTS(SELECT * FROM [_columnas] WHERE [tabla]='ter_sector'
AND [columna]='sector_codigo' AND[mostrarEnGrilla]=1 AND[ordenGrilla]=1 AND[requerido]=1 AND[tipo]='varchar' AND[defecto]=0)
BEGIN
INSERT INTO [_columnas]
([tabla] ,[columna] ,[mostrarEnGrilla],[ordenGrilla],[requerido] ,[tipo],[defecto],[tamano])
 VALUES
 ('ter_sector' ,'sector_codigo',1 ,1 ,1 ,'varchar' ,0 ,100)
END



IF NOT EXISTS(SELECT * FROM [_columnas] WHERE [tabla]='ter_sector'
AND [columna]='id' AND[mostrarEnGrilla]=1 AND[ordenGrilla]=1 AND[requerido]=1 AND[tipo]='int'AND[defecto]=0)
BEGIN
INSERT INTO [_columnas]
([tabla] ,[columna] ,[mostrarEnGrilla],[ordenGrilla],[requerido] ,[tipo],[defecto],[tamano])
 VALUES
 ('ter_sector' ,'id',1 ,1 ,1 ,'int' ,0 ,300)
END


IF NOT EXISTS(SELECT * FROM [_columnas] WHERE [tabla]='ter_sector'
AND [columna]='uid' AND[mostrarEnGrilla]=1 AND[ordenGrilla]=1 AND[requerido]=1 AND[tipo]='varchar'AND[defecto]=0)
BEGIN
INSERT INTO [_columnas]
([tabla] ,[columna] ,[mostrarEnGrilla],[ordenGrilla],[requerido] ,[tipo],[defecto],[tamano])
 VALUES
 ('ter_sector' ,'uid',1 ,1 ,1 ,'varchar' ,0 ,100)
END

IF NOT EXISTS(SELECT * FROM [_columnas] WHERE [tabla]='ter_sector'
AND [columna]='eid' AND[mostrarEnGrilla]=1 AND[ordenGrilla]=1 AND[requerido]=1 AND[tipo]='varchar'AND[defecto]=0)
BEGIN
INSERT INTO [_columnas]
([tabla] ,[columna] ,[mostrarEnGrilla],[ordenGrilla],[requerido] ,[tipo],[defecto],[tamano])
 VALUES
 ('ter_sector' ,'eid',1 ,1 ,1 ,'varchar' ,0 ,100)
END

IF NOT EXISTS(SELECT * FROM [_columnas] WHERE [tabla]='ter_sector'
AND [columna]='id_usuario_modifico' AND[mostrarEnGrilla]=1 AND[ordenGrilla]=1 AND[requerido]=1 AND[tipo]='varchar'AND[defecto]=0)
BEGIN
INSERT INTO [_columnas]
([tabla] ,[columna] ,[mostrarEnGrilla],[ordenGrilla],[requerido] ,[tipo],[defecto],[tamano])
 VALUES
 ('ter_sector' ,'id_usuario_modifico',1 ,1 ,1 ,'varchar' ,0 ,100)
END

IF NOT EXISTS(SELECT * FROM [_columnas] WHERE [tabla]='ter_sector'
AND [columna]='id_usuario_creo' AND[mostrarEnGrilla]=1 AND[ordenGrilla]=1 AND[requerido]=1 AND[tipo]='varchar'AND[defecto]=0)
BEGIN
INSERT INTO [_columnas]
([tabla] ,[columna] ,[mostrarEnGrilla],[ordenGrilla],[requerido] ,[tipo],[defecto],[tamano])
 VALUES
 ('ter_sector' ,'id_usuario_creo',1 ,1 ,1 ,'varchar' ,0 ,100)
END

IF NOT EXISTS(SELECT * FROM [_columnas] WHERE [tabla]='ter_sector'
AND [columna]='fechaModificacion' AND[mostrarEnGrilla]=1 AND[ordenGrilla]=1 AND[requerido]=1 AND[tipo]='smalldatetime'AND[defecto]=0)
BEGIN
INSERT INTO [_columnas]
([tabla] ,[columna] ,[mostrarEnGrilla],[ordenGrilla],[requerido] ,[tipo],[defecto],[tamano])
 VALUES
 ('ter_sector' ,'fechaModificacion',1 ,1 ,1 ,'smalldatetime' ,0 ,100)
END

IF NOT EXISTS(SELECT * FROM [_columnas] WHERE [tabla]='ter_sector'
AND [columna]='fechaCreacion' AND[mostrarEnGrilla]=1 AND[ordenGrilla]=1 AND[requerido]=1 AND[tipo]='smalldatetime'AND[defecto]=0)
BEGIN
INSERT INTO [_columnas]
([tabla] ,[columna] ,[mostrarEnGrilla],[ordenGrilla],[requerido] ,[tipo],[defecto],[tamano])
 VALUES
 ('ter_sector' ,'fechaCreacion',1 ,1 ,1 ,'smalldatetime' ,0 ,100)
END


IF NOT EXISTS(SELECT * FROM [_columnas] WHERE [tabla]='ter_sector'
AND [columna]='active' AND[mostrarEnGrilla]=1 AND[ordenGrilla]=1 AND[requerido]=1 AND[tipo]='int'AND[defecto]=0)
BEGIN
INSERT INTO [_columnas]
([tabla] ,[columna] ,[mostrarEnGrilla],[ordenGrilla],[requerido] ,[tipo],[defecto],[tamano])
 VALUES
 ('ter_sector' ,'active',1 ,1 ,1 ,'int' ,0 ,100)
END