CREATE TABLE DEV_EGRESO ( 
DEG_TIP VARCHAR(3) NOT NULL,
DEG_NUM INT DEFAULT (0) NOT NULL,
DEG_CIA CHAR(2) DEFAULT ('01') NOT NULL,
DEG_FEC SMALLDATETIME,
DEG_TEG VARCHAR(3) NOT NULL,
DEG_EGR INT DEFAULT (0),
DEG_CEG CHAR(2) DEFAULT ('01'),
DEG_NIT VARCHAR(11),
DEG_VAL MONEY DEFAULT (0),
DEG_EFE BIT DEFAULT (0) NOT NULL,
DEG_CTA VARCHAR(3)
 CONSTRAINT PK_DEV_EGRESO PRIMARY KEY CLUSTERED (DEG_TIP,DEG_NUM,DEG_CIA),
 CONSTRAINT CK__DEV_EGRES__DEG_C__7A9C383C CHECK ((len([DEG_CIA]) > 0)),
 CONSTRAINT CK__DEV_EGRES__DEG_T__77BFCB91 CHECK ((len([DEG_TIP]) > 0)),
 CONSTRAINT CK__DEV_EGRES__DEG_T__7B905C75 CHECK ((len([DEG_TEG]) > 0)))
CREATE TABLE EGRESOS ( 
EGR_TIP VARCHAR(3) NOT NULL,
EGR_NUM INT DEFAULT (0) NOT NULL,
EGR_CIA CHAR(2) DEFAULT ('01') NOT NULL,
EGR_FEC SMALLDATETIME,
EGR_NIT VARCHAR(11),
EGR_CTA VARCHAR(3),
EGR_CHE VARCHAR(20),
EGR_FCH SMALLDATETIME,
EGR_EFE BIT DEFAULT (0) NOT NULL,
EGR_VAL MONEY DEFAULT (0) NOT NULL,
EGR_CON VARCHAR(3) DEFAULT ('GAS') NOT NULL,
EGR_DEV BIT DEFAULT (0) NOT NULL,
EGR_NDV INT DEFAULT (0),
EGR_FDV SMALLDATETIME
 CONSTRAINT PK_EGRESOS PRIMARY KEY CLUSTERED (EGR_TIP,EGR_NUM,EGR_CIA),
 CONSTRAINT CK__EGRESOS__EGR_CIA__0519C6AF CHECK ((len([EGR_CIA]) > 0)),
 CONSTRAINT CK__EGRESOS__EGR_CON__08EA5793 CHECK ((len([EGR_CON]) > 0)),
 CONSTRAINT CK__EGRESOS__EGR_TIP__023D5A04 CHECK ((len([EGR_TIP]) > 0)))
CREATE TABLE INFCOM ( 
COM_TIP VARCHAR(3) NOT NULL,
COM_NUM INT DEFAULT (0) NOT NULL,
COM_CIA CHAR(2) DEFAULT ('01') NOT NULL,
COM_OBS VARCHAR(100),
COM_FEC SMALLDATETIME,
COM_NIT VARCHAR(11),
COM_CHE VARCHAR(20),
COM_CTA VARCHAR(3),
COM_USU VARCHAR(10),
COM_TCN VARCHAR(3),
COM_NCN INT DEFAULT(0),
COM_TCF VARCHAR(3),
COM_NCF INT DEFAULT(0)
 CONSTRAINT PK_INFCOM PRIMARY KEY CLUSTERED (COM_TIP,COM_NUM,COM_CIA),
 CONSTRAINT CK__INFCOM__COM_CIA__108B795B CHECK ((len([COM_CIA]) > 0)),
 CONSTRAINT CK__INFCOM__COM_TIP__0DAF0CB0 CHECK ((len([COM_TIP]) > 0)))
CREATE TABLE MOVIMIENTO ( 
MOV_TIP VARCHAR(3) NOT NULL,
MOV_NUM INT DEFAULT ((0)) NOT NULL,
MOV_CIA CHAR(2) DEFAULT ('01') NOT NULL,
MOV_ITM INT DEFAULT ((0)) NOT NULL,
MOV_FEC SMALLDATETIME NOT NULL,
MOV_CUE VARCHAR(16) NOT NULL,
MOV_DET VARCHAR(100),
MOV_DEB MONEY DEFAULT ((0)),
MOV_CRE MONEY DEFAULT ((0)),
MOV_CON VARCHAR(3),
MOV_NIT VARCHAR(11),
MOV_BAS MONEY DEFAULT ((0)),
MOV_TDC VARCHAR(3),
MOV_DOC INT DEFAULT ((0)),
MOV_CDC CHAR(2) DEFAULT ('01'),
MOV_TFA VARCHAR(3),
MOV_FAC VARCHAR(10),
MOV_NV DECIMAL(10,4) DEFAULT ((0)),
MOV_CFA CHAR(2) DEFAULT ('01'),
MOV_FVC SMALLDATETIME,
MOV_CTA VARCHAR(3),
MOV_CHE VARCHAR(20),
MOV_INT BIT DEFAULT ((0)) NOT NULL,
MOV_VEN CHAR(1) DEFAULT ('N') NOT NULL,
MOV_CC VARCHAR(3),
MOV_AGE VARCHAR(9) DEFAULT ('N'),
MOV_USU VARCHAR(10)
 CONSTRAINT PK_MOVIMIENTO PRIMARY KEY CLUSTERED (MOV_TIP,MOV_NUM,MOV_CIA,MOV_ITM),
 CONSTRAINT CK__MOVIMIENT__MOV_C__164452B1 CHECK ((len([MOV_CIA])>(0))),
 CONSTRAINT CK__MOVIMIENT__MOV_C__182C9B23 CHECK ((len([MOV_CUE])>(0))),
 CONSTRAINT CK__MOVIMIENT__MOV_T__1367E606 CHECK ((len([MOV_TIP])>(0))),
 CONSTRAINT CK__MOVIMIENT__MOV_V__21B6055D CHECK ((len([MOV_VEN])>(0))))
CREATE TABLE NIIFCOMPROBANTE ( 
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_TRN VARCHAR(10) DEFAULT ('NIIF') NOT NULL,
COM_NIT VARCHAR(11),
COM_TCG VARCHAR(3),
COM_NCG INT DEFAULT ((0)) NOT NULL,
COM_TCN VARCHAR(3),
COM_NCN INT DEFAULT ((0)) NOT NULL,
COM_DEV BIT DEFAULT ((0)) NOT NULL,
COM_OBS VARCHAR(250),
COM_USU VARCHAR(10)
 CONSTRAINT PK_NIIFCOMPROBANTE PRIMARY KEY CLUSTERED (COM_TIP,COM_NUM,COM_CIA),
 CONSTRAINT CK_NIIFCOMPROBANTECOM_CIA CHECK ((len([COM_CIA])>(0))),
 CONSTRAINT CK_NIIFCOMPROBANTECOM_TIP CHECK ((len([COM_TIP])>(0))),
 CONSTRAINT CK_NIIFCOMPROBANTECOM_TRN CHECK ((len([COM_TRN])>(0))))
CREATE TABLE NIIFDETALLE ( 
MOV_TIP VARCHAR(3) NOT NULL,
MOV_NUM INT DEFAULT ((0)) NOT NULL,
MOV_CIA CHAR(2) DEFAULT ('01') NOT NULL,
MOV_ITM INT DEFAULT ((0)) NOT NULL,
MOV_FEC SMALLDATETIME NOT NULL,
MOV_CUE VARCHAR(16) NOT NULL,
MOV_DET VARCHAR(250) NOT NULL,
MOV_DEB MONEY DEFAULT ((0)),
MOV_CRE MONEY DEFAULT ((0)),
MOV_CON VARCHAR(3),
MOV_NIT VARCHAR(11),
MOV_BAS MONEY DEFAULT ((0)),
MOV_TDC VARCHAR(3),
MOV_DOC INT DEFAULT ((0)),
MOV_CDC CHAR(2) DEFAULT ('01'),
MOV_TFA VARCHAR(3),
MOV_FAC VARCHAR(10),
MOV_NV DECIMAL(14,4) DEFAULT ((0)),
MOV_CFA CHAR(2) DEFAULT ('01'),
MOV_FVC SMALLDATETIME,
MOV_CTA VARCHAR(3),
MOV_CHE VARCHAR(20),
MOV_INT BIT DEFAULT ((0)) NOT NULL,
MOV_VEN CHAR(1) DEFAULT ('N'),
MOV_CC VARCHAR(3),
MOV_AGE VARCHAR(9) DEFAULT ('N'),
MOV_USU VARCHAR(10),
MOV_CCG VARCHAR(16)
 CONSTRAINT PK_NIIFDETALLE PRIMARY KEY CLUSTERED (MOV_TIP,MOV_NUM,MOV_CIA,MOV_ITM),
 CONSTRAINT CK_NIIFDETALLEMOV_CIA CHECK ((len([MOV_CIA])>(0))),
 CONSTRAINT CK_NIIFDETALLEMOV_CUE CHECK ((len([MOV_CUE])>(0))),
 CONSTRAINT CK_NIIFDETALLEMOV_DET CHECK ((len([MOV_DET])>(0))),
 CONSTRAINT CK_NIIFDETALLEMOV_TIP CHECK ((len([MOV_TIP])>(0))))
GO
 CREATE NONCLUSTERED INDEX IX_MOVIMIENTOMOV_FEC ON MOVIMIENTO(MOV_FEC)
 CREATE NONCLUSTERED INDEX IX_MOVIMIENTOMOV_NUM ON MOVIMIENTO(MOV_TIP,MOV_NUM,MOV_CIA)
 CREATE NONCLUSTERED INDEX IX_MOVIMIENTOMOV_CUE ON MOVIMIENTO(MOV_CUE)

GO
 CREATE NONCLUSTERED INDEX IX_NIIFCOMPROBANTECOM_FEC ON NIIFCOMPROBANTE(COM_FEC)

GO
 CREATE NONCLUSTERED INDEX IX_NIIFDETALLEMOV_FEC ON NIIFDETALLE(MOV_FEC)
 CREATE NONCLUSTERED INDEX IX_NIIFDETALLEMOV_CUE ON NIIFDETALLE(MOV_CUE)

GO
