CREATE TABLE ANTCLIE ( 
ANT_TIP VARCHAR(3) NOT NULL,
ANT_NUM INT DEFAULT (0) NOT NULL,
ANT_CIA CHAR(2) DEFAULT ('01') NOT NULL,
ANT_FEC SMALLDATETIME,
ANT_VAL MONEY DEFAULT (0),
ANT_ABO MONEY DEFAULT (0),
ANT_NIT VARCHAR(11) NOT NULL,
ANT_AGE VARCHAR(9) DEFAULT ('N'),
ANT_VEN VARCHAR(11)
 CONSTRAINT PK_ANTCLIE PRIMARY KEY CLUSTERED (ANT_TIP,ANT_NUM,ANT_CIA),
 CONSTRAINT CK__ANTCLIE__ANT_CIA__7A9C383C CHECK ((len([ANT_CIA]) > 0)),
 CONSTRAINT CK__ANTCLIE__ANT_NIT__7D78A4E7 CHECK ((len([ANT_NIT]) > 0)),
 CONSTRAINT CK__ANTCLIE__ANT_TIP__77BFCB91 CHECK ((len([ANT_TIP]) > 0)))
CREATE TABLE ANTICIPOS ( 
ANT_TIP VARCHAR(3) DEFAULT ('ANT') NOT NULL,
ANT_NUM INT DEFAULT (0) NOT NULL,
ANT_CIA CHAR(2) DEFAULT ('01') NOT NULL,
ANT_FEC SMALLDATETIME NOT NULL,
ANT_TPL VARCHAR(3) DEFAULT ('PLT') NOT NULL,
ANT_PLA INT DEFAULT (0) NOT NULL,
ANT_CPL CHAR(2) DEFAULT ('01') NOT NULL,
ANT_VEH VARCHAR(10) NOT NULL,
ANT_NIT VARCHAR(11) NOT NULL,
ANT_VAL MONEY DEFAULT (0) NOT NULL,
ANT_APL MONEY DEFAULT (0),
ANT_OFI VARCHAR(8),
ANT_CDP VARCHAR(3),
ANT_CON VARCHAR(3),
ANT_EFE BIT DEFAULT (0) NOT NULL,
ANT_CHE VARCHAR(20),
ANT_FCH SMALLDATETIME,
ANT_CTA VARCHAR(3),
ANT_CUE VARCHAR(16),
ANT_GIR VARCHAR(150),
ANT_OBS VARCHAR(250),
ANT_DEV BIT DEFAULT (0) NOT NULL,
ANT_NDV INT DEFAULT (0),
ANT_FDV SMALLDATETIME,
ANT_CMP VARCHAR(3),
ANT_NCP INT DEFAULT (0),
ANT_CDT VARCHAR(11),
ANT_USU VARCHAR(10),
ANT_CGR VARCHAR(11)
 CONSTRAINT PK_ANTICIPOS PRIMARY KEY CLUSTERED (ANT_TIP,ANT_NUM,ANT_CIA),
 CONSTRAINT CK__ANTICIPOS__ANT_C__0519C6AF CHECK ((len([ANT_CIA]) > 0)),
 CONSTRAINT CK__ANTICIPOS__ANT_C__09DE7BCC CHECK ((len([ANT_CPL]) > 0)),
 CONSTRAINT CK__ANTICIPOS__ANT_N__0BC6C43E CHECK ((len([ANT_NIT]) > 0)),
 CONSTRAINT CK__ANTICIPOS__ANT_T__023D5A04 CHECK ((len([ANT_TIP]) > 0)),
 CONSTRAINT CK__ANTICIPOS__ANT_T__07020F21 CHECK ((len([ANT_TPL]) > 0)),
 CONSTRAINT CK__ANTICIPOS__ANT_V__0AD2A005 CHECK ((len([ANT_VEH]) > 0)))
CREATE TABLE APLANT ( 
APL_TIP VARCHAR(3) NOT NULL,
APL_NUM INT DEFAULT (0) NOT NULL,
APL_CIA CHAR(2) DEFAULT ('01') NOT NULL,
APL_ITM SMALLINT DEFAULT (0) NOT NULL,
APL_FEC SMALLDATETIME,
APL_ANT INT DEFAULT (0) NOT NULL,
APL_TAN VARCHAR(3) DEFAULT ('ANT') NOT NULL,
APL_CAN CHAR(2) DEFAULT ('01') NOT NULL,
APL_VAL MONEY DEFAULT (0),
APL_DEV MONEY DEFAULT (0),
APL_NIT VARCHAR(11),
APL_VEH VARCHAR(10)
 CONSTRAINT PK_APLANT PRIMARY KEY CLUSTERED (APL_TIP,APL_NUM,APL_CIA,APL_ITM),
 CONSTRAINT CK__APLANT__APL_CAN__1CF15040 CHECK ((len([APL_CAN]) > 0)),
 CONSTRAINT CK__APLANT__APL_CIA__173876EA CHECK ((len([APL_CIA]) > 0)),
 CONSTRAINT CK__APLANT__APL_TAN__1B0907CE CHECK ((len([APL_TAN]) > 0)),
 CONSTRAINT CK__APLANT__APL_TIP__145C0A3F CHECK ((len([APL_TIP]) > 0)))
CREATE TABLE APLICAANT ( 
APL_TDC VARCHAR(3) NOT NULL,
APL_DOC INT DEFAULT (0) NOT NULL,
APL_CIA CHAR(2) DEFAULT ('01') NOT NULL,
APL_ITM SMALLINT DEFAULT (0) NOT NULL,
APL_TIP VARCHAR(3) NOT NULL,
APL_NUM INT DEFAULT (0) NOT NULL,
APL_CDC CHAR(2) DEFAULT ('01') NOT NULL,
APL_FEC SMALLDATETIME,
APL_VAL MONEY DEFAULT (0) NOT NULL,
APL_NIT VARCHAR(11) NOT NULL,
APL_AGE VARCHAR(9) DEFAULT ('N'),
APL_VEN VARCHAR(11)
 CONSTRAINT PK_APLICAANT PRIMARY KEY CLUSTERED (APL_TDC,APL_DOC,APL_CIA,APL_ITM),
 CONSTRAINT CK__APLICAANT__APL_C__24927208 CHECK ((len([APL_CIA]) > 0)),
 CONSTRAINT CK__APLICAANT__APL_C__29572725 CHECK ((len([APL_CDC]) > 0)),
 CONSTRAINT CK__APLICAANT__APL_N__2B3F6F97 CHECK ((len([APL_NIT]) > 0)),
 CONSTRAINT CK__APLICAANT__APL_T__21B6055D CHECK ((len([APL_TDC]) > 0)),
 CONSTRAINT CK__APLICAANT__APL_T__267ABA7A CHECK ((len([APL_TIP]) > 0)))
CREATE TABLE APLICACXP ( 
APL_CMP VARCHAR(3) NOT NULL,
APL_NCP INT DEFAULT (0) NOT NULL,
APL_CIA CHAR(2) DEFAULT ('01') NOT NULL,
APL_LIN SMALLINT DEFAULT (1) NOT NULL,
APL_FEC SMALLDATETIME,
APL_CUE VARCHAR(16),
APL_NIT VARCHAR(11) NOT NULL,
APL_TIP VARCHAR(3) NOT NULL,
APL_NUM VARCHAR(20) NOT NULL,
APL_CDC CHAR(2) DEFAULT ('01') NOT NULL,
APL_NV SMALLINT DEFAULT (0),
APL_VAL MONEY DEFAULT (0),
APL_DEV MONEY DEFAULT (0)
 CONSTRAINT PK_APLICACXP PRIMARY KEY CLUSTERED (APL_CMP,APL_NCP,APL_CIA,APL_LIN),
 CONSTRAINT CK__APLICACXP__APL_C__2F10007B CHECK ((len([APL_CMP]) > 0)),
 CONSTRAINT CK__APLICACXP__APL_C__31EC6D26 CHECK ((len([APL_CIA]) > 0)),
 CONSTRAINT CK__APLICACXP__APL_C__37A5467C CHECK ((len([APL_CDC]) > 0)),
 CONSTRAINT CK__APLICACXP__APL_N__33D4B598 CHECK ((len([APL_NIT]) > 0)),
 CONSTRAINT CK__APLICACXP__APL_N__35BCFE0A CHECK ((len([APL_NUM]) > 0)),
 CONSTRAINT CK__APLICACXP__APL_T__34C8D9D1 CHECK ((len([APL_TIP]) > 0)))
CREATE TABLE APLICAVCE ( 
APL_TDC VARCHAR(3) NOT NULL,
APL_DOC INT DEFAULT (0) NOT NULL,
APL_CIA CHAR(2) DEFAULT ('01') NOT NULL,
APL_LIN SMALLINT DEFAULT (0) NOT NULL,
APL_TIP VARCHAR(3) NOT NULL,
APL_NUM INT DEFAULT (0) NOT NULL,
APL_NV SMALLINT DEFAULT (0) NOT NULL,
APL_CDC CHAR(2) DEFAULT ('01') NOT NULL,
APL_FEC SMALLDATETIME,
APL_VAL MONEY DEFAULT (0),
APL_DEV MONEY DEFAULT (0),
APL_DCT MONEY DEFAULT (0),
APL_VEN VARCHAR(11),
APL_CMS DECIMAL(10,4) DEFAULT (0),
APL_NIT VARCHAR(11),
APL_AGE VARCHAR(9) DEFAULT ('N')
 CONSTRAINT PK_APLICAVCE PRIMARY KEY CLUSTERED (APL_TDC,APL_DOC,APL_CIA,APL_LIN),
 CONSTRAINT CK__APLICAVCE__APL_C__403A8C7D CHECK ((len([APL_CIA]) > 0)),
 CONSTRAINT CK__APLICAVCE__APL_C__45F365D3 CHECK ((len([APL_CDC]) > 0)),
 CONSTRAINT CK__APLICAVCE__APL_T__3D5E1FD2 CHECK ((len([APL_TDC]) > 0)),
 CONSTRAINT CK__APLICAVCE__APL_T__4222D4EF CHECK ((len([APL_TIP]) > 0)))
CREATE TABLE CHEQUES ( 
CHE_NUM VARCHAR(20) NOT NULL,
CHE_BAN VARCHAR(3) NOT NULL,
CHE_CIA CHAR(2) DEFAULT ('01') NOT NULL,
CHE_FEC SMALLDATETIME,
CHE_POS SMALLDATETIME,
CHE_VAL MONEY DEFAULT (0) NOT NULL,
CHE_CLI VARCHAR(11) NOT NULL,
CHE_AGE VARCHAR(9) DEFAULT ('N'),
CHE_REF VARCHAR(50),
CHE_CIU VARCHAR(8),
CHE_REC INT DEFAULT (0),
CHE_TIP VARCHAR(3),
CHE_DOC INT DEFAULT (0),
CHE_CDC CHAR(2) DEFAULT ('01'),
CHE_FDC SMALLDATETIME,
CHE_CNS INT DEFAULT (0),
CHE_CCN CHAR(2) DEFAULT ('01'),
CHE_FCN SMALLDATETIME,
CHE_CTA VARCHAR(3),
CHE_DEV BIT DEFAULT (0) NOT NULL,
CHE_VEN VARCHAR(11)
 CONSTRAINT PK_CHEQUES PRIMARY KEY CLUSTERED (CHE_NUM,CHE_BAN,CHE_CIA),
 CONSTRAINT CK__CHEQUES__CHE_BAN__4E88ABD4 CHECK ((len([CHE_BAN]) > 0)),
 CONSTRAINT CK__CHEQUES__CHE_CIA__5070F446 CHECK ((len([CHE_CIA]) > 0)),
 CONSTRAINT CK__CHEQUES__CHE_CLI__52593CB8 CHECK ((len([CHE_CLI]) > 0)),
 CONSTRAINT CK__CHEQUES__CHE_NUM__4D94879B CHECK ((len([CHE_NUM]) > 0)))
CREATE TABLE COMPROBANTES ( 
COM_TIP VARCHAR(3) NOT NULL,
COM_NUM INT DEFAULT (0) NOT NULL,
COM_CIA CHAR(2) DEFAULT ('01') NOT NULL,
COM_FEC SMALLDATETIME,
COM_ELI BIT DEFAULT (0) NOT NULL,
COM_ANU BIT DEFAULT (0) NOT NULL,
COM_DEV BIT DEFAULT (0) NOT NULL,
COM_NDV INT DEFAULT (0),
COM_FDV SMALLDATETIME,
COM_DOC VARCHAR(3),
COM_NDC INT DEFAULT (0)
 CONSTRAINT PK_COMPROBANTES PRIMARY KEY CLUSTERED (COM_TIP,COM_NUM,COM_CIA),
 CONSTRAINT CK__COMPROBAN__COM_C__5EBF139D CHECK ((len([COM_CIA]) > 0)),
 CONSTRAINT CK__COMPROBAN__COM_T__5BE2A6F2 CHECK ((len([COM_TIP]) > 0)))
CREATE TABLE CREDITOS ( 
CRE_NUM VARCHAR(20) NOT NULL,
CRE_CIA CHAR(2) DEFAULT ('01') NOT NULL,
CRE_NIT VARCHAR(11) NOT NULL,
CRE_PLA INT DEFAULT (0) NOT NULL,
CRE_ITM SMALLINT DEFAULT (0),
CRE_FEC SMALLDATETIME,
CRE_CUE VARCHAR(16),
CRE_VAL MONEY DEFAULT (0) NOT NULL,
CRE_CAN BIT DEFAULT (0) NOT NULL,
CRE_TDC VARCHAR(3) DEFAULT ('FCR'),
CRE_FAC INT DEFAULT ((-1)),
CRE_CFA CHAR(2),
CRE_FCA SMALLDATETIME,
CRE_DEV BIT DEFAULT (0) NOT NULL,
CRE_NDV INT DEFAULT ((-1)),
CRE_OBS VARCHAR(50),
CRE_AGE VARCHAR(9) DEFAULT ('N'),
CRE_VEH VARCHAR(10),
CRE_PRO VARCHAR(16),
CRE_GAL DECIMAL(14,4) DEFAULT (0),
CRE_NVH VARCHAR(15),
CRE_DEP VARCHAR(50),
CRE_KMT DECIMAL(14,4) DEFAULT (0),
CRE_CDT VARCHAR(20),
CRE_NCD VARCHAR(100),
CRE_NVA INT DEFAULT (0),
CRE_PRE MONEY DEFAULT ((0)),
CRE_BAS MONEY DEFAULT ((0)),
CRE_PEC MONEY DEFAULT ((0))
 CONSTRAINT PK_CREDITOS PRIMARY KEY CLUSTERED (CRE_NUM,CRE_CIA,CRE_NIT),
 CONSTRAINT CK__CREDITOS__CRE_CI__68487DD7 CHECK ((len([CRE_CIA]) > 0)),
 CONSTRAINT CK__CREDITOS__CRE_NI__693CA210 CHECK ((len([CRE_NIT]) > 0)),
 CONSTRAINT CK__CREDITOS__CRE_NU__66603565 CHECK ((len([CRE_NUM]) > 0)))
CREATE TABLE CUENTASPORPAGAR ( 
VCE_TIP VARCHAR(3) NOT NULL,
VCE_NUM VARCHAR(20) NOT NULL,
VCE_NV SMALLINT DEFAULT (0) NOT NULL,
VCE_NIT VARCHAR(11) NOT NULL,
VCE_CIA CHAR(2) DEFAULT ('01') NOT NULL,
VCE_CUE VARCHAR(16) NOT NULL,
VCE_DOC INT DEFAULT (0),
VCE_CDC CHAR(2) DEFAULT ('01'),
VCE_EMI SMALLDATETIME,
VCE_FEC SMALLDATETIME,
VCE_VAL MONEY DEFAULT (0),
VCE_ABO MONEY DEFAULT (0),
VCE_CMP VARCHAR(3),
VCE_NCP INT DEFAULT (0)
 CONSTRAINT PK_CUENTASPORPAGAR PRIMARY KEY CLUSTERED (VCE_TIP,VCE_NUM,VCE_NV,VCE_NIT,VCE_CIA),
 CONSTRAINT CK__CUENTASPO__VCE_C__7A672E12 CHECK ((len([VCE_CIA]) > 0)),
 CONSTRAINT CK__CUENTASPO__VCE_C__7B5B524B CHECK ((len([VCE_CUE]) > 0)),
 CONSTRAINT CK__CUENTASPO__VCE_N__76969D2E CHECK ((len([VCE_NUM]) > 0)),
 CONSTRAINT CK__CUENTASPO__VCE_N__787EE5A0 CHECK ((len([VCE_NIT]) > 0)),
 CONSTRAINT CK__CUENTASPO__VCE_T__75A278F5 CHECK ((len([VCE_TIP]) > 0)))
CREATE TABLE DOCUMENTOS ( 
DOC_TIP VARCHAR(3) NOT NULL,
DOC_NUM INT DEFAULT (0) NOT NULL,
DOC_CIA CHAR(2) DEFAULT ('01') NOT NULL,
DOC_FEC SMALLDATETIME,
DOC_FAC VARCHAR(20),
DOC_CLI VARCHAR(11),
DOC_ELI BIT DEFAULT (0) NOT NULL,
DOC_ANU BIT DEFAULT (0) NOT NULL,
DOC_DEV BIT DEFAULT (0) NOT NULL,
DOC_NDV INT DEFAULT (0),
DOC_FDV SMALLDATETIME,
DOC_CMP VARCHAR(3),
DOC_NCP INT DEFAULT (0)
 CONSTRAINT PK_DOCUMENTOS PRIMARY KEY CLUSTERED (DOC_TIP,DOC_NUM,DOC_CIA),
 CONSTRAINT CK__DOCUMENTO__DOC_C__05D8E0BE CHECK ((len([DOC_CIA]) > 0)),
 CONSTRAINT CK__DOCUMENTO__DOC_T__02FC7413 CHECK ((len([DOC_TIP]) > 0)))
CREATE TABLE EGROPAGO ( 
EGO_TIP VARCHAR(3) NOT NULL,
EGO_NUM INT DEFAULT (0) NOT NULL,
EGO_CIA CHAR(2) DEFAULT ('01') NOT NULL,
EGO_TDC VARCHAR(3) DEFAULT ('ODP') NOT NULL,
EGO_DOC INT DEFAULT (0) NOT NULL,
EGO_CDC CHAR(2) DEFAULT ('01') NOT NULL,
EGO_FEC SMALLDATETIME NOT NULL,
EGO_PLA INT DEFAULT (0) NOT NULL,
EGO_CPL CHAR(2) DEFAULT ('01') NOT NULL,
EGO_VAL MONEY DEFAULT (0)
 CONSTRAINT PK_EGROPAGO PRIMARY KEY CLUSTERED (EGO_TIP,EGO_NUM,EGO_CIA,EGO_TDC,EGO_DOC,EGO_CDC),
 CONSTRAINT CK__EGROPAGO__EGO_CD__151B244E CHECK ((len([EGO_CDC]) > 0)),
 CONSTRAINT CK__EGROPAGO__EGO_CI__10566F31 CHECK ((len([EGO_CIA]) > 0)),
 CONSTRAINT CK__EGROPAGO__EGO_CP__17F790F9 CHECK ((len([EGO_CPL]) > 0)),
 CONSTRAINT CK__EGROPAGO__EGO_TD__123EB7A3 CHECK ((len([EGO_TDC]) > 0)),
 CONSTRAINT CK__EGROPAGO__EGO_TI__0D7A0286 CHECK ((len([EGO_TIP]) > 0)))
CREATE TABLE LOGTRANS ( 
LOG_TIP VARCHAR(3) NOT NULL,
LOG_NUM INT DEFAULT (0) NOT NULL,
LOG_CIA CHAR(2) DEFAULT ('01') NOT NULL,
LOG_INI BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_LOGTRANS PRIMARY KEY CLUSTERED (LOG_TIP,LOG_NUM,LOG_CIA),
 CONSTRAINT CK__LOGTRANS__LOG_CI__1EA48E88 CHECK ((len([LOG_CIA]) > 0)),
 CONSTRAINT CK__LOGTRANS__LOG_TI__1BC821DD CHECK ((len([LOG_TIP]) > 0)))
CREATE TABLE LOTES ( 
LOT_COD VARCHAR(16) NOT NULL,
LOT_SEC VARCHAR(3) NOT NULL,
LOT_NUM VARCHAR(20) NOT NULL,
LOT_CIA CHAR(2) DEFAULT ('01') NOT NULL,
LOT_FEC SMALLDATETIME,
LOT_VCE SMALLDATETIME,
LOT_SAL DECIMAL(14,4) DEFAULT (0),
LOT_DIA SMALLINT DEFAULT (0),
LOT_SAN DECIMAL(14,4) DEFAULT (0)
 CONSTRAINT PK_LOTES PRIMARY KEY CLUSTERED (LOT_COD,LOT_SEC,LOT_NUM,LOT_CIA),
 CONSTRAINT CK__LOTES__LOT_CIA__2645B050 CHECK ((len([LOT_CIA]) > 0)),
 CONSTRAINT CK__LOTES__LOT_COD__22751F6C CHECK ((len([LOT_COD]) > 0)),
 CONSTRAINT CK__LOTES__LOT_NUM__245D67DE CHECK ((len([LOT_NUM]) > 0)),
 CONSTRAINT CK__LOTES__LOT_SEC__236943A5 CHECK ((len([LOT_SEC]) > 0)))
CREATE TABLE MOVREF ( 
MOV_TIP VARCHAR(3) NOT NULL,
MOV_NUM INT DEFAULT (0) NOT NULL,
MOV_CIA CHAR(2) DEFAULT ('01') NOT NULL,
MOV_ITM SMALLINT DEFAULT (0) NOT NULL,
MOV_COD VARCHAR(16) NOT NULL,
MOV_SEC VARCHAR(3) NOT NULL,
MOV_FEC SMALLDATETIME,
MOV_TAN VARCHAR(3),
MOV_ENT DECIMAL(14,4) DEFAULT (0),
MOV_SAL DECIMAL(14,4) DEFAULT (0),
MOV_LOT VARCHAR(20)
 CONSTRAINT PK_MOVREF PRIMARY KEY CLUSTERED (MOV_TIP,MOV_NUM,MOV_CIA,MOV_ITM),
 CONSTRAINT CK__MOVREF__MOV_CIA__2EDAF651 CHECK ((len([MOV_CIA]) > 0)),
 CONSTRAINT CK__MOVREF__MOV_COD__30C33EC3 CHECK ((len([MOV_COD]) > 0)),
 CONSTRAINT CK__MOVREF__MOV_SEC__31B762FC CHECK ((len([MOV_SEC]) > 0)),
 CONSTRAINT CK__MOVREF__MOV_TIP__2BFE89A6 CHECK ((len([MOV_TIP]) > 0)))
CREATE TABLE NIIFCOMPINDICE ( 
COM_TIP VARCHAR(3) NOT NULL,
COM_NUM INT DEFAULT ((0)) NOT NULL,
COM_CIA CHAR(2) DEFAULT ('01') NOT NULL,
COM_FEC SMALLDATETIME NOT NULL,
COM_ELI BIT DEFAULT ((0)) NOT NULL,
COM_ANU BIT DEFAULT ((0)) NOT NULL,
COM_DEV BIT DEFAULT ((0)) NOT NULL,
COM_NDV INT DEFAULT ((0)),
COM_FDV SMALLDATETIME,
COM_DOC VARCHAR(3),
COM_NDC INT DEFAULT ((0))
 CONSTRAINT PK_NIIFCOMPINDICE PRIMARY KEY CLUSTERED (COM_TIP,COM_NUM,COM_CIA),
 CONSTRAINT CK_NIIFCOMPINDICECOM_CIA CHECK ((len([COM_CIA])>(0))),
 CONSTRAINT CK_NIIFCOMPINDICECOM_TIP CHECK ((len([COM_TIP])>(0))))
CREATE TABLE PROMEDIOS ( 
PRO_COD VARCHAR(16) NOT NULL,
PRO_CIA CHAR(2) DEFAULT ('01') NOT NULL,
PRO_PRA MONEY DEFAULT (0),
PRO_CPM MONEY DEFAULT (0),
PRO_COS MONEY DEFAULT (0),
PRO_PRE MONEY DEFAULT (0)
 CONSTRAINT PK_PROMEDIOS PRIMARY KEY CLUSTERED (PRO_COD,PRO_CIA),
 CONSTRAINT CK__PROMEDIOS__PRO_C__367C1819 CHECK ((len([PRO_COD]) > 0)),
 CONSTRAINT CK__PROMEDIOS__PRO_C__3864608B CHECK ((len([PRO_CIA]) > 0)))
CREATE TABLE RELDOC ( 
DOC_ID INT DEFAULT (0) NOT NULL,
DOC_CIA CHAR(2) DEFAULT ('01') NOT NULL,
DOC_TIP VARCHAR(3) NOT NULL,
DOC_NUM INT DEFAULT (0) NOT NULL,
DOC_FEC SMALLDATETIME NOT NULL,
DOC_TDC CHAR(3) NOT NULL,
DOC_DOC INT DEFAULT (0) NOT NULL,
DOC_CDC CHAR(2) DEFAULT ('01') NOT NULL,
DOC_FDC SMALLDATETIME,
DOC_ITM SMALLINT DEFAULT (0),
DOC_REF VARCHAR(15),
DOC_VAL MONEY DEFAULT (0)
 CONSTRAINT PK_RELDOC PRIMARY KEY CLUSTERED (DOC_ID,DOC_CIA,DOC_TIP,DOC_NUM),
 CONSTRAINT CK__RELDOC__DOC_CDC__46B27FE2 CHECK ((len([DOC_CDC]) > 0)),
 CONSTRAINT CK__RELDOC__DOC_CIA__40F9A68C CHECK ((len([DOC_CIA]) > 0)),
 CONSTRAINT CK__RELDOC__DOC_TDC__43D61337 CHECK ((len([DOC_TDC]) > 0)),
 CONSTRAINT CK__RELDOC__DOC_TIP__41EDCAC5 CHECK ((len([DOC_TIP]) > 0)))
CREATE TABLE SALDOCUENIT ( 
SAL_CUE VARCHAR(16) NOT NULL,
SAL_NIT VARCHAR(11) NOT NULL,
SAL_CIA CHAR(2) DEFAULT ('01') NOT NULL,
SAL_SAL MONEY DEFAULT (0)
 CONSTRAINT PK_SALDOCUENIT PRIMARY KEY CLUSTERED (SAL_CUE,SAL_NIT,SAL_CIA),
 CONSTRAINT CK__SALDOCUEN__SAL_C__4B7734FF CHECK ((len([SAL_CUE]) > 0)),
 CONSTRAINT CK__SALDOCUEN__SAL_C__4E53A1AA CHECK ((len([SAL_CIA]) > 0)),
 CONSTRAINT CK__SALDOCUEN__SAL_N__4C6B5938 CHECK ((len([SAL_NIT]) > 0)))
CREATE TABLE SALDOSCLI ( 
SAL_CLI VARCHAR(11) NOT NULL,
SAL_CIA CHAR(2) DEFAULT ('01') NOT NULL,
SAL_AGE VARCHAR(9) DEFAULT ('N') NOT NULL,
SAL_SAL MONEY DEFAULT (0),
SAL_SAN MONEY DEFAULT (0)
 CONSTRAINT PK_SALDOSCLI PRIMARY KEY CLUSTERED (SAL_CLI,SAL_CIA,SAL_AGE),
 CONSTRAINT CK__SALDOSCLI__SAL_A__55F4C372 CHECK ((len([SAL_AGE]) > 0)),
 CONSTRAINT CK__SALDOSCLI__SAL_C__5224328E CHECK ((len([SAL_CLI]) > 0)),
 CONSTRAINT CK__SALDOSCLI__SAL_C__540C7B00 CHECK ((len([SAL_CIA]) > 0)))
CREATE TABLE SALDOSREF ( 
SAL_COD VARCHAR(16) NOT NULL,
SAL_SEC VARCHAR(3) NOT NULL,
SAL_CIA CHAR(2) DEFAULT ('01') NOT NULL,
SAL_SAL DECIMAL(14,4) DEFAULT (0),
SAL_ANT DECIMAL(14,4) DEFAULT (0),
SAL_CAN MONEY DEFAULT (0)
 CONSTRAINT PK_SALDOSREF PRIMARY KEY CLUSTERED (SAL_COD,SAL_SEC,SAL_CIA),
 CONSTRAINT CK__SALDOSREF__SAL_C__5AB9788F CHECK ((len([SAL_COD]) > 0)),
 CONSTRAINT CK__SALDOSREF__SAL_C__5D95E53A CHECK ((len([SAL_CIA]) > 0)),
 CONSTRAINT CK__SALDOSREF__SAL_S__5BAD9CC8 CHECK ((len([SAL_SEC]) > 0)))
CREATE TABLE SALDOSTAN ( 
SAL_TAN VARCHAR(3) NOT NULL,
SAL_CIA CHAR(2) DEFAULT ('01') NOT NULL,
SAL_SAL DECIMAL(14,4) DEFAULT (0),
SAL_ANT DECIMAL(14,4) DEFAULT (0),
SAL_CAN MONEY DEFAULT (0)
 CONSTRAINT PK_SALDOSTAN PRIMARY KEY CLUSTERED (SAL_TAN,SAL_CIA),
 CONSTRAINT CK__SALDOSTAN__SAL_C__65370702 CHECK ((len([SAL_CIA]) > 0)),
 CONSTRAINT CK__SALDOSTAN__SAL_T__634EBE90 CHECK ((len([SAL_TAN]) > 0)))
CREATE TABLE SERIALES ( 
SER_COD VARCHAR(16) NOT NULL,
SER_NUM VARCHAR(20) NOT NULL,
SER_CIA CHAR(2) DEFAULT ('01') NOT NULL,
SER_ENT SMALLDATETIME,
SER_SAL SMALLDATETIME,
SER_ACT BIT DEFAULT (0) NOT NULL,
SER_SEC VARCHAR(3),
SER_EST VARCHAR(3),
SER_OBS VARCHAR(50),
SER_DC1 VARCHAR(10),
SER_DC2 VARCHAR(10),
SER_FD1 SMALLDATETIME,
SER_FD2 SMALLDATETIME
 CONSTRAINT PK_SERIALES PRIMARY KEY CLUSTERED (SER_COD,SER_NUM,SER_CIA),
 CONSTRAINT CK__SERIALES__SER_CI__6DCC4D03 CHECK ((len([SER_CIA]) > 0)),
 CONSTRAINT CK__SERIALES__SER_CO__6AEFE058 CHECK ((len([SER_COD]) > 0)),
 CONSTRAINT CK__SERIALES__SER_NU__6BE40491 CHECK ((len([SER_NUM]) > 0)))
CREATE TABLE VCRE_DETALLE ( 
DET_NUM VARCHAR(20) NOT NULL,
DET_CIA CHAR(2) NOT NULL,
DET_ITM INT DEFAULT (0) NOT NULL,
DET_COD VARCHAR(16) NOT NULL,
DET_DES VARCHAR(100),
DET_SEC VARCHAR(3) NOT NULL,
DET_CAN DECIMAL(10,4) DEFAULT (0) NOT NULL,
DET_VAL MONEY DEFAULT (0) NOT NULL,
DET_IVA DECIMAL(10,4) DEFAULT (0) NOT NULL,
DET_VIV MONEY DEFAULT (0) NOT NULL,
DET_DCT DECIMAL(10,4) DEFAULT (0) NOT NULL,
DET_VDC MONEY DEFAULT (0) NOT NULL,
DET_VEN VARCHAR(11) NOT NULL,
DET_CMS DECIMAL(10,4) DEFAULT (0) NOT NULL,
DET_SER BIT DEFAULT (0) NOT NULL,
DET_VEH VARCHAR(10),
DET_OPE VARCHAR(11),
DET_CMO VARCHAR(3)
 CONSTRAINT PK_VCRE_DETALLE PRIMARY KEY CLUSTERED (DET_NUM,DET_CIA,DET_ITM),
 CONSTRAINT CK_VCRE_DETALLEDET_CIA CHECK ((len([DET_CIA]) > 0)),
 CONSTRAINT CK_VCRE_DETALLEDET_COD CHECK ((len([DET_COD]) > 0)),
 CONSTRAINT CK_VCRE_DETALLEDET_NUM CHECK ((len([DET_NUM]) > 0)),
 CONSTRAINT CK_VCRE_DETALLEDET_SEC CHECK ((len([DET_SEC]) > 0)),
 CONSTRAINT CK_VCRE_DETALLEDET_VEN CHECK ((len([DET_VEN]) > 0)))
CREATE TABLE VCREDITO ( 
CRE_NUM VARCHAR(20) NOT NULL,
CRE_CIA CHAR(2) NOT NULL,
CRE_FEC SMALLDATETIME NOT NULL,
CRE_CLI VARCHAR(11) NOT NULL,
CRE_AGE VARCHAR(9) DEFAULT ('N'),
CRE_VAL MONEY DEFAULT (0) NOT NULL,
CRE_VEN VARCHAR(11) NOT NULL,
CRE_CMS DECIMAL(10,4) DEFAULT (0) NOT NULL,
CRE_OBS VARCHAR(100),
CRE_VEH VARCHAR(10),
CRE_TDC VARCHAR(3),
CRE_DOC INT DEFAULT (0) NOT NULL,
CRE_CDC CHAR(2),
CRE_FDC SMALLDATETIME,
CRE_DEV BIT DEFAULT (0) NOT NULL,
CRE_NDV INT DEFAULT (0),
CRE_FDV SMALLDATETIME,
CRE_USU VARCHAR(10),
CRE_IND INT DEFAULT (0),
CRE_PED VARCHAR(50),
CRE_KMT VARCHAR(50),
CRE_CC VARCHAR(3)
 CONSTRAINT PK_VCREDITO PRIMARY KEY CLUSTERED (CRE_NUM,CRE_CIA),
 CONSTRAINT CK_VCREDITOCRE_CIA CHECK ((len([CRE_CIA]) > 0)),
 CONSTRAINT CK_VCREDITOCRE_CLI CHECK ((len([CRE_CLI]) > 0)),
 CONSTRAINT CK_VCREDITOCRE_NUM CHECK ((len([CRE_NUM]) > 0)),
 CONSTRAINT CK_VCREDITOCRE_VEN CHECK ((len([CRE_VEN]) > 0)))
CREATE TABLE VENCIMIENTOS ( 
VCE_NUM INT DEFAULT (0) NOT NULL,
VCE_TIP VARCHAR(3) NOT NULL,
VCE_NV SMALLINT DEFAULT (1) NOT NULL,
VCE_CIA CHAR(2) DEFAULT ('01') NOT NULL,
VCE_EMI SMALLDATETIME NOT NULL,
VCE_FEC SMALLDATETIME NOT NULL,
VCE_VAL MONEY DEFAULT (0),
VCE_ABO MONEY DEFAULT (0),
VCE_NIT VARCHAR(11) NOT NULL,
VCE_AGE VARCHAR(9) DEFAULT ('N'),
VCE_VEN VARCHAR(11),
VCE_CMS DECIMAL(10,4) DEFAULT (0),
VCE_FUP SMALLDATETIME,
VCE_CON VARCHAR(3),
VCE_DOC VARCHAR(10),
VCE_NOT INT DEFAULT (0),
VCE_FUL SMALLDATETIME
 CONSTRAINT PK_VENCIMIENTOS PRIMARY KEY CLUSTERED (VCE_NUM,VCE_TIP,VCE_NV,VCE_CIA),
 CONSTRAINT CK__VENCIMIEN__VCE_C__756D6ECB CHECK ((len([VCE_CIA]) > 0)),
 CONSTRAINT CK__VENCIMIEN__VCE_T__72910220 CHECK ((len([VCE_TIP]) > 0)))
GO
 CREATE NONCLUSTERED INDEX IX_ANTICIPOSANT_PLA ON ANTICIPOS(ANT_TPL,ANT_PLA,ANT_CPL)
 CREATE NONCLUSTERED INDEX IX_ANTICIPOSANT_VEH ON ANTICIPOS(ANT_VEH)
 CREATE NONCLUSTERED INDEX IX_ANTICIPOSANT_NIT ON ANTICIPOS(ANT_NIT)

GO
 CREATE NONCLUSTERED INDEX IX_APLICAVCEAPL_NUM ON APLICAVCE(APL_TIP,APL_NUM,APL_CDC,APL_NV)
 CREATE NONCLUSTERED INDEX IX_APLICAVCEAPL_FEC ON APLICAVCE(APL_FEC)
 CREATE NONCLUSTERED INDEX IX_APLICAVCEAPL_NIT ON APLICAVCE(APL_NIT)

GO
 CREATE NONCLUSTERED INDEX IX_MOVREFMOV_COD ON MOVREF(MOV_COD)
 CREATE NONCLUSTERED INDEX IX_MOVREFMOV_SEC ON MOVREF(MOV_SEC)
 CREATE NONCLUSTERED INDEX IX_MOVREFMOV_FEC ON MOVREF(MOV_FEC)
 CREATE NONCLUSTERED INDEX IX_MOVREFMOV_NUM ON MOVREF(MOV_TIP,MOV_NUM,MOV_CIA)

GO
 CREATE NONCLUSTERED INDEX IX_NIIFCOMPINDICECOM_FEC ON NIIFCOMPINDICE(COM_FEC)

GO
 CREATE NONCLUSTERED INDEX IX_RELDOCDOC_FEC ON RELDOC(DOC_FEC)
 CREATE NONCLUSTERED INDEX IX_RELDOCDOC_DOC ON RELDOC(DOC_TDC,DOC_DOC,DOC_CDC)

GO
 CREATE NONCLUSTERED INDEX IX_VENCIMIENTOSVCE_EMI ON VENCIMIENTOS(VCE_EMI)
 CREATE NONCLUSTERED INDEX IX_VENCIMIENTOSVCE_NIT ON VENCIMIENTOS(VCE_NIT)

GO
