CREATE TABLE CAMPOS ( 
CAM_NOM VARCHAR(10) NOT NULL,
CAM_TAB VARCHAR(20) NOT NULL,
CAM_DES VARCHAR(30) NOT NULL,
CAM_TIP CHAR(1) DEFAULT ('T') NOT NULL,
CAM_LIS BIT DEFAULT (0) NOT NULL,
CAM_TBL VARCHAR(20),
CAM_CL1 VARCHAR(10),
CAM_CL2 VARCHAR(10),
CAM_CRI VARCHAR(30),
CAM_DOC VARCHAR(30) DEFAULT ('ALL')
 CONSTRAINT PK_CAMPOS PRIMARY KEY CLUSTERED (CAM_NOM,CAM_TAB),
 CONSTRAINT CK_CAMPOSCAM_DES CHECK ((len([CAM_DES]) > 0)),
 CONSTRAINT CK_CAMPOSCAM_NOM CHECK ((len([CAM_NOM]) > 0)),
 CONSTRAINT CK_CAMPOSCAM_TAB CHECK ((len([CAM_TAB]) > 0)),
 CONSTRAINT CK_CAMPOSCAM_TIP CHECK ((len([CAM_TIP]) > 0)))
CREATE TABLE CIERRES ( 
CIE_NUM SMALLINT DEFAULT (0) NOT NULL,
CIE_CIA CHAR(2) DEFAULT ('01') NOT NULL,
CIE_ENE BIT DEFAULT (0) NOT NULL,
CIE_FEB BIT DEFAULT (0) NOT NULL,
CIE_MAR BIT DEFAULT (0) NOT NULL,
CIE_ABR BIT DEFAULT (0) NOT NULL,
CIE_MAY BIT DEFAULT (0) NOT NULL,
CIE_JUN BIT DEFAULT (0) NOT NULL,
CIE_JUL BIT DEFAULT (0) NOT NULL,
CIE_AGO BIT DEFAULT (0) NOT NULL,
CIE_SEP BIT DEFAULT (0) NOT NULL,
CIE_OCT BIT DEFAULT (0) NOT NULL,
CIE_NOV BIT DEFAULT (0) NOT NULL,
CIE_DIC BIT DEFAULT (0) NOT NULL,
CIE_ANO BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_CIERRES PRIMARY KEY CLUSTERED (CIE_NUM,CIE_CIA),
 CONSTRAINT CK_CIERRESCIE_CIA CHECK ((len([CIE_CIA]) > 0)))
CREATE TABLE COMPANIAS ( 
CIA_COD CHAR(2) DEFAULT ('01') NOT NULL,
CIA_DES VARCHAR(30) NOT NULL,
CIA_PER SMALLDATETIME NOT NULL,
CIA_DIR VARCHAR(255),
CIA_FEC SMALLDATETIME NOT NULL,
CIA_CIU VARCHAR(8)
 CONSTRAINT PK_COMPANIAS PRIMARY KEY CLUSTERED (CIA_COD),
 CONSTRAINT CK_COMPANIASCIA_COD CHECK ((len([CIA_COD]) > 0)),
 CONSTRAINT CK_COMPANIASCIA_DES CHECK ((len([CIA_DES]) > 0)))
CREATE TABLE CONAUTORIZA ( 
CON_COD VARCHAR(3) NOT NULL,
CON_DES VARCHAR(30) NOT NULL
 CONSTRAINT PK_CONAUTORIZA PRIMARY KEY CLUSTERED (CON_COD),
 CONSTRAINT CK_CONAUTORIZACON_COD CHECK ((len([CON_COD]) > 0)),
 CONSTRAINT CK_CONAUTORIZACON_DES CHECK ((len([CON_DES]) > 0)))
CREATE TABLE CONPERMISOS ( 
CON_MEN VARCHAR(10) NOT NULL,
CON_COD VARCHAR(3) NOT NULL,
CON_DES VARCHAR(100) NOT NULL
 CONSTRAINT PK_CONPERMISOS PRIMARY KEY CLUSTERED (CON_MEN,CON_COD),
 CONSTRAINT CK_CONPERMISOSCON_COD CHECK ((len([CON_COD]) > 0)),
 CONSTRAINT CK_CONPERMISOSCON_DES CHECK ((len([CON_DES]) > 0)),
 CONSTRAINT CK_CONPERMISOSCON_MEN CHECK ((len([CON_MEN]) > 0)))
CREATE TABLE EMPRESA ( 
EMP_NIT VARCHAR(13) NOT NULL,
EMP_NOM VARCHAR(50) NOT NULL,
EMP_DIR VARCHAR(50) NOT NULL,
EMP_TEL VARCHAR(20) NOT NULL,
EMP_FAX VARCHAR(20) NOT NULL,
EMP_CIU VARCHAR(20),
EMP_INT VARCHAR(60),
EMP_COR VARCHAR(60)
 CONSTRAINT PK_EMPRESA PRIMARY KEY CLUSTERED (EMP_NIT),
 CONSTRAINT CK_EMPRESAEMP_DIR CHECK ((len([EMP_DIR]) > 0)),
 CONSTRAINT CK_EMPRESAEMP_FAX CHECK ((len([EMP_FAX]) > 0)),
 CONSTRAINT CK_EMPRESAEMP_NIT CHECK ((len([EMP_NIT]) > 0)),
 CONSTRAINT CK_EMPRESAEMP_NOM CHECK ((len([EMP_NOM]) > 0)),
 CONSTRAINT CK_EMPRESAEMP_TEL CHECK ((len([EMP_TEL]) > 0)))
CREATE TABLE ENTIDADES ( 
ENT_TB1 VARCHAR(20) NOT NULL,
ENT_TB2 VARCHAR(20) NOT NULL,
ENT_CAM VARCHAR(10) NOT NULL,
ENT_BAS VARCHAR(10) NOT NULL,
ENT_VAL BIT DEFAULT (0) NOT NULL,
ENT_FOR BIT DEFAULT (0) NOT NULL,
ENT_CLA VARCHAR(10)
 CONSTRAINT PK_ENTIDADES PRIMARY KEY CLUSTERED (ENT_TB1,ENT_TB2,ENT_CAM),
 CONSTRAINT CK_ENTIDADESENT_BAS CHECK ((len([ENT_BAS]) > 0)),
 CONSTRAINT CK_ENTIDADESENT_CAM CHECK ((len([ENT_CAM]) > 0)),
 CONSTRAINT CK_ENTIDADESENT_TB1 CHECK ((len([ENT_TB1]) > 0)),
 CONSTRAINT CK_ENTIDADESENT_TB2 CHECK ((len([ENT_TB2]) > 0)))
CREATE TABLE FACAUTO ( 
REL_FAC INT DEFAULT (0) NOT NULL,
REL_CIA CHAR(2) DEFAULT ('01') NOT NULL,
REL_CLI VARCHAR(16),
REL_AGE VARCHAR(9) DEFAULT ('N'),
REL_GRU VARCHAR(3),
REL_FEC SMALLDATETIME
 CONSTRAINT PK_FACAUTO PRIMARY KEY CLUSTERED (REL_FAC,REL_CIA),
 CONSTRAINT CK_FACAUTOREL_CIA CHECK ((len([REL_CIA]) > 0)))
CREATE TABLE FORMATOS ( 
FOR_ID VARCHAR(3) NOT NULL,
FOR_TIP VARCHAR(3) NOT NULL,
FOR_DES VARCHAR(30) NOT NULL,
FOR_ARC VARCHAR(15) NOT NULL,
FOR_PRE BIT DEFAULT (0) NOT NULL,
FOR_VER BIT DEFAULT (0) NOT NULL,
FOR_COP SMALLINT DEFAULT (1),
FOR_ORI SMALLINT DEFAULT (1),
FOR_PAP INT DEFAULT (1),
FOR_SEP BIT DEFAULT (0) NOT NULL,
FOR_DBS VARCHAR(40)
 CONSTRAINT PK_FORMATOS PRIMARY KEY CLUSTERED (FOR_ID,FOR_TIP),
 CONSTRAINT CK_FORMATOSFOR_ARC CHECK ((len([FOR_ARC]) > 0)),
 CONSTRAINT CK_FORMATOSFOR_DES CHECK ((len([FOR_DES]) > 0)),
 CONSTRAINT CK_FORMATOSFOR_ID CHECK ((len([FOR_ID]) > 0)),
 CONSTRAINT CK_FORMATOSFOR_TIP CHECK ((len([FOR_TIP]) > 0)))
CREATE TABLE LICENCIA ( 
LIC_ID CHAR(2) DEFAULT ('01') NOT NULL,
LIC_NIT VARCHAR(13),
LIC_NOM VARCHAR(100) NOT NULL,
LIC_DES VARCHAR(100),
LIC_DIR VARCHAR(250),
LIC_TEL VARCHAR(22),
LIC_FAX VARCHAR(10),
LIC_CIU VARCHAR(20),
LIC_FVC SMALLDATETIME,
LIC_LOG VARCHAR(80),
LIC_SER VARCHAR(80) NOT NULL,
LIC_REG VARCHAR(40) DEFAULT ('REGIMEN COMUN'),
LIC_NUM VARCHAR(20),
LIC_VCE SMALLDATETIME,
LIC_JUR VARCHAR(40),
LIC_MEM VARCHAR(250),
LIC_FEC SMALLDATETIME,
LIC_INI SMALLDATETIME,
LIC_CC VARCHAR(3) NOT NULL,
LIC_CTA VARCHAR(3) NOT NULL,
LIC_RET BIT DEFAULT (0) NOT NULL,
LIC_PAI VARCHAR(50) DEFAULT ('COLOMBIA'),
LIC_EML VARCHAR(100)
 CONSTRAINT PK_LICENCIA PRIMARY KEY CLUSTERED (LIC_ID),
 CONSTRAINT CK_LICENCIALIC_CC CHECK ((len([LIC_CC]) > 0)),
 CONSTRAINT CK_LICENCIALIC_CTA CHECK ((len([LIC_CTA]) > 0)),
 CONSTRAINT CK_LICENCIALIC_ID CHECK ((len([LIC_ID]) > 0)),
 CONSTRAINT CK_LICENCIALIC_NOM CHECK ((len([LIC_NOM]) > 0)),
 CONSTRAINT CK_LICENCIALIC_SER CHECK ((len([LIC_SER]) > 0)))
CREATE TABLE LISTADOS ( 
LIS_TIP VARCHAR(3) NOT NULL,
LIS_ID CHAR(2) NOT NULL,
LIS_FOR VARCHAR(50),
LIS_ARC VARCHAR(15),
LIS_DBS VARCHAR(40),
LIS_PAP SMALLINT DEFAULT (1),
LIS_ORI SMALLINT DEFAULT (1)
 CONSTRAINT PK_LISTADOS PRIMARY KEY CLUSTERED (LIS_TIP,LIS_ID),
 CONSTRAINT CK_LISTADOSLIS_ID CHECK ((len([LIS_ID]) > 0)),
 CONSTRAINT CK_LISTADOSLIS_TIP CHECK ((len([LIS_TIP]) > 0)))
CREATE TABLE MENUES ( 
MEN_MOD VARCHAR(3) NOT NULL,
MEN_SUB VARCHAR(3) NOT NULL,
MEN_ID SMALLINT DEFAULT (0) NOT NULL,
MEN_NOM VARCHAR(60) NOT NULL,
MEN_ALI VARCHAR(10) NOT NULL,
MEN_FRM VARCHAR(10),
MEN_PER VARCHAR(15),
MEN_NIV SMALLINT DEFAULT (0)
 CONSTRAINT PK_MENUES PRIMARY KEY CLUSTERED (MEN_MOD,MEN_SUB,MEN_ID),
 CONSTRAINT IX_MENUESMEN_ALI UNIQUE NONCLUSTERED (MEN_ALI),
 CONSTRAINT CK_MENUESMEN_ALI CHECK ((len([MEN_ALI]) > 0)),
 CONSTRAINT CK_MENUESMEN_MOD CHECK ((len([MEN_MOD]) > 0)),
 CONSTRAINT CK_MENUESMEN_NOM CHECK ((len([MEN_NOM]) > 0)),
 CONSTRAINT CK_MENUESMEN_SUB CHECK ((len([MEN_SUB]) > 0)))
CREATE TABLE MODULOS ( 
MOD_COD VARCHAR(3) NOT NULL,
MOD_DES VARCHAR(15) NOT NULL
 CONSTRAINT PK_MODULOS PRIMARY KEY CLUSTERED (MOD_COD),
 CONSTRAINT CK_MODULOSMOD_COD CHECK ((len([MOD_COD]) > 0)),
 CONSTRAINT CK_MODULOSMOD_DES CHECK ((len([MOD_DES]) > 0)))
CREATE TABLE NIIFCIERRES ( 
CIE_NUM SMALLINT NOT NULL,
CIE_CIA CHAR(2) DEFAULT ('01') NOT NULL,
CIE_ENE BIT DEFAULT ((0)) NOT NULL,
CIE_FEB BIT DEFAULT ((0)) NOT NULL,
CIE_MAR BIT DEFAULT ((0)) NOT NULL,
CIE_ABR BIT DEFAULT ((0)) NOT NULL,
CIE_MAY BIT DEFAULT ((0)) NOT NULL,
CIE_JUN BIT DEFAULT ((0)) NOT NULL,
CIE_JUL BIT DEFAULT ((0)) NOT NULL,
CIE_AGO BIT DEFAULT ((0)) NOT NULL,
CIE_SEP BIT DEFAULT ((0)) NOT NULL,
CIE_OCT BIT DEFAULT ((0)) NOT NULL,
CIE_NOV BIT DEFAULT ((0)) NOT NULL,
CIE_DIC BIT DEFAULT ((0)) NOT NULL,
CIE_ANO BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_NIIFCIERRES PRIMARY KEY CLUSTERED (CIE_NUM,CIE_CIA),
 CONSTRAINT CK_NIIFCIERRESCIE_CIA CHECK ((len([CIE_CIA])>(0))))
CREATE TABLE OTROSPER ( 
OTR_USU VARCHAR(8) NOT NULL,
OTR_MEN VARCHAR(10) NOT NULL,
OTR_PER VARCHAR(3) NOT NULL,
OTR_ACT BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_OTROSPER PRIMARY KEY CLUSTERED (OTR_USU,OTR_MEN,OTR_PER),
 CONSTRAINT CK_OTROSPEROTR_MEN CHECK ((len([OTR_MEN]) > 0)),
 CONSTRAINT CK_OTROSPEROTR_PER CHECK ((len([OTR_PER]) > 0)),
 CONSTRAINT CK_OTROSPEROTR_USU CHECK ((len([OTR_USU]) > 0)))
CREATE TABLE PARAMETROS ( 
PAR_COD VARCHAR(3) NOT NULL,
PAR_ORD SMALLINT DEFAULT (0) NOT NULL,
PAR_DES VARCHAR(100),
PAR_VAL BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_PARAMETROS PRIMARY KEY CLUSTERED (PAR_COD),
 CONSTRAINT CK_PARAMETROSPAR_COD CHECK ((len([PAR_COD]) > 0)))
CREATE TABLE PERMISOS ( 
PER_USU VARCHAR(8) NOT NULL,
PER_MEN VARCHAR(10) NOT NULL,
PER_AGR BIT DEFAULT (0) NOT NULL,
PER_ACT BIT DEFAULT (0) NOT NULL,
PER_ELI BIT DEFAULT (0) NOT NULL,
PER_VER BIT DEFAULT (0) NOT NULL,
PER_MOD VARCHAR(3),
PER_SUB VARCHAR(3),
PER_ID SMALLINT DEFAULT (0),
PER_DES VARCHAR(60)
 CONSTRAINT PK_PERMISOS PRIMARY KEY CLUSTERED (PER_USU,PER_MEN),
 CONSTRAINT CK_PERMISOSPER_MEN CHECK ((len([PER_MEN]) > 0)),
 CONSTRAINT CK_PERMISOSPER_USU CHECK ((len([PER_USU]) > 0)))
CREATE TABLE PWDS ( 
PWD_ID SMALLINT DEFAULT (0) NOT NULL,
PWD_DES VARCHAR(20) NOT NULL,
PWD_CON VARCHAR(10)
 CONSTRAINT PK_PWDS PRIMARY KEY CLUSTERED (PWD_ID),
 CONSTRAINT CK_PWDSPWD_DES CHECK ((len([PWD_DES]) > 0)))
CREATE TABLE TABLAS ( 
TBL_COD VARCHAR(3) NOT NULL,
TBL_NOM VARCHAR(20) NOT NULL,
TBL_CM1 VARCHAR(10) NOT NULL,
TBL_CM2 VARCHAR(10) NOT NULL,
TBL_DC1 VARCHAR(30),
TBL_DC2 VARCHAR(30),
TBL_TIT VARCHAR(30),
TBL_ALI VARCHAR(10) NOT NULL,
TBL_LON SMALLINT DEFAULT (0),
TBL_BAS VARCHAR(3)
 CONSTRAINT PK_TABLAS PRIMARY KEY CLUSTERED (TBL_COD),
 CONSTRAINT CK_TABLASTBL_ALI CHECK ((len([TBL_ALI]) > 0)),
 CONSTRAINT CK_TABLASTBL_CM1 CHECK ((len([TBL_CM1]) > 0)),
 CONSTRAINT CK_TABLASTBL_CM2 CHECK ((len([TBL_CM2]) > 0)),
 CONSTRAINT CK_TABLASTBL_COD CHECK ((len([TBL_COD]) > 0)),
 CONSTRAINT CK_TABLASTBL_NOM CHECK ((len([TBL_NOM]) > 0)))
CREATE TABLE TPAPEL ( 
PAP_ID SMALLINT DEFAULT (0) NOT NULL,
PAP_DES VARCHAR(30) NOT NULL
 CONSTRAINT PK_TPAPEL PRIMARY KEY CLUSTERED (PAP_ID),
 CONSTRAINT CK_TPAPELPAP_DES CHECK ((len([PAP_DES]) > 0)))
CREATE TABLE UBICACIONES ( 
UBI_COD VARCHAR(15) NOT NULL,
UBI_DBS VARCHAR(40) NOT NULL
 CONSTRAINT PK_UBICACIONES PRIMARY KEY CLUSTERED (UBI_COD),
 CONSTRAINT CK_UBICACIONESUBI_COD CHECK ((len([UBI_COD]) > 0)),
 CONSTRAINT CK_UBICACIONESUBI_DBS CHECK ((len([UBI_DBS]) > 0)))
CREATE TABLE USUARIOS ( 
USU_ID VARCHAR(8) NOT NULL,
USU_NOM VARCHAR(30) NOT NULL,
USU_CLV VARCHAR(9) NOT NULL,
USU_NIV SMALLINT DEFAULT (0) NOT NULL,
USU_TER CHAR(2),
USU_FEC SMALLDATETIME,
USU_ACT BIT DEFAULT (0) NOT NULL,
USU_FUC SMALLDATETIME,
USU_DIA INT DEFAULT (0),
USU_SEC VARCHAR(3),
USU_PRE CHAR(1) DEFAULT ('1'),
USU_CIA CHAR(2),
USU_ATL VARCHAR(30)
 CONSTRAINT PK_USUARIOS PRIMARY KEY CLUSTERED (USU_ID),
 CONSTRAINT CK_USUARIOSUSU_CLV CHECK ((len([USU_CLV]) > 0)),
 CONSTRAINT CK_USUARIOSUSU_ID CHECK ((len([USU_ID]) > 0)),
 CONSTRAINT CK_USUARIOSUSU_NOM CHECK ((len([USU_NOM]) > 0)))

CREATE TABLE [dbo].[UVT](
	UVT_PER INT NOT NULL DEFAULT ((0)),
    UVT_VAL DECIMAL(14, 4) NOT NULL DEFAULT (0),
 CONSTRAINT [PK_UVT] PRIMARY KEY CLUSTERED (UVT_PER)
)
GO


GO
