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(16),
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(16),
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(16),
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)),
COM_SOP BIT DEFAULT ((0)),
COM_RES VARCHAR(3),
COM_DCS VARCHAR(500),
COM_VAL MONEY 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(16),
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),
MOV_CUN VARCHAR(16),
MOV_TDS VARCHAR(3),
MOV_NDS INT DEFAULT ((0)),
MOV_CDS CHAR(2)
 CONSTRAINT PK_MOVIMIENTO PRIMARY KEY NONCLUSTERED (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(16),
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(16),
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),
MOV_TDS VARCHAR(3),
MOV_NDS INT DEFAULT ((0)),
MOV_CDS CHAR(2)
 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))))
CREATE TABLE NIIFREVELACIONES ( 
REV_TIP VARCHAR(3) NOT NULL,
REV_NUM INT DEFAULT ((0)) NOT NULL,
REV_CIA CHAR(2) DEFAULT ('01') NOT NULL,
REV_ITM INT DEFAULT ((0)) NOT NULL,
REV_TRV VARCHAR(10) DEFAULT ('COMP') NOT NULL,
REV_TIT VARCHAR(250),
REV_OBS VARCHAR(5000) NOT NULL,
REV_CUE VARCHAR(16),
REV_FEC SMALLDATETIME NOT NULL,
REV_USU VARCHAR(10) NOT NULL
 CONSTRAINT PK_NIIFREVELACIONES PRIMARY KEY CLUSTERED (REV_TIP,REV_NUM,REV_CIA,REV_ITM),
 CONSTRAINT CK_NIIFREVELACIONESREV_CIA CHECK ((len([REV_CIA])>(0))),
 CONSTRAINT CK_NIIFREVELACIONESREV_TIP CHECK ((len([REV_TIP])>(0))),
 CONSTRAINT CK_NIIFREVELACIONESREV_TRV CHECK ((len([REV_TRV])>(0))),
 CONSTRAINT CK_NIIFREVELACIONESREV_USU CHECK ((len([REV_USU])>(0))))
GO
 CREATE CLUSTERED INDEX IX_MOVIMIENTOMOV_FEC ON MOVIMIENTO(MOV_FEC,MOV_CUE,MOV_CIA)
 CREATE NONCLUSTERED INDEX IX_MOVIMIENTOMOV_NUM ON MOVIMIENTO(MOV_TIP,MOV_NUM,MOV_CIA)

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
