CREATE TABLE CIERRES ( 
CIE_ANO INT DEFAULT ((0)) NOT NULL,
CIE_MES INT DEFAULT ((0)) NOT NULL,
CIE_PER INT DEFAULT ((0)) NOT NULL,
CIE_ACT BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_CIERRES PRIMARY KEY CLUSTERED (CIE_ANO,CIE_MES,CIE_PER))
CREATE TABLE CONCEPTOS ( 
CON_COD VARCHAR(3) NOT NULL,
CON_DES VARCHAR(50) NOT NULL,
CON_TIP VARCHAR(3) DEFAULT ('DED')
 CONSTRAINT PK_CONCEPTOS PRIMARY KEY CLUSTERED (CON_COD),
 CONSTRAINT CK_CONCEPTOSCON_COD CHECK ((len([CON_COD])>(0))),
 CONSTRAINT CK_CONCEPTOSCON_DES CHECK ((len([CON_DES])>(0))))
CREATE TABLE DETLIQUIDA ( 
DET_MES INT DEFAULT ((0)) NOT NULL,
DET_PER INT DEFAULT ((0)) NOT NULL,
DET_ANO INT DEFAULT ((0)) NOT NULL,
DET_CDT VARCHAR(11) NOT NULL,
DET_CON VARCHAR(3) NOT NULL,
DET_VAL MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_DETLIQUIDA PRIMARY KEY CLUSTERED (DET_MES,DET_PER,DET_ANO,DET_CDT,DET_CON),
 CONSTRAINT CK_DETLIQUIDADET_CDT CHECK ((len([DET_CDT])>(0))),
 CONSTRAINT CK_DETLIQUIDADET_CON CHECK ((len([DET_CON])>(0))))
CREATE TABLE LIQUIDA ( 
LIQ_MES INT DEFAULT ((0)) NOT NULL,
LIQ_ANO INT DEFAULT ((0)) NOT NULL,
LIQ_PER INT DEFAULT ((0)) NOT NULL,
LIQ_CON VARCHAR(11) NOT NULL,
LIQ_FEC SMALLDATETIME NOT NULL,
LIQ_PLA VARCHAR(10),
LIQ_BAS MONEY DEFAULT ((0)) NOT NULL,
LIQ_TOT MONEY DEFAULT ((0)) NOT NULL,
LIQ_AUX MONEY DEFAULT ((0)) NOT NULL,
LIQ_ODV MONEY DEFAULT ((0)) NOT NULL,
LIQ_SEG MONEY DEFAULT ((0)) NOT NULL,
LIQ_ANT MONEY DEFAULT ((0)) NOT NULL,
LIQ_TEL MONEY DEFAULT ((0)) NOT NULL,
LIQ_OTR MONEY DEFAULT ((0)) NOT NULL,
LIQ_SAN MONEY DEFAULT ((0)) NOT NULL,
LIQ_SAL MONEY DEFAULT ((0)) NOT NULL,
LIQ_OBS VARCHAR(100),
LIQ_USU VARCHAR(10)
 CONSTRAINT PK_LIQUIDA PRIMARY KEY CLUSTERED (LIQ_MES,LIQ_ANO,LIQ_PER,LIQ_CON),
 CONSTRAINT CK_LIQUIDALIQ_CON CHECK ((len([LIQ_CON])>(0))))
CREATE TABLE LOG ( 
LOG_ID BIGINT IDENTITY ( 1,1 ) NOT NULL,
LOG_USU VARCHAR(8) NOT NULL,
LOG_FEC SMALLDATETIME,
LOG_HOR VARCHAR(15),
LOG_OBS VARCHAR(50)
 CONSTRAINT PK_LOG PRIMARY KEY CLUSTERED (LOG_ID),
 CONSTRAINT CK_LOGLOG_USU CHECK ((len([LOG_USU])>(0))))
CREATE TABLE PARAMETROS ( 
PAR_ID INT IDENTITY ( 1,1 ) NOT NULL,
PAR_DIR VARCHAR(240),
PAR_SML MONEY DEFAULT ((0)),
PAR_SEG DECIMAL(12,4) DEFAULT ((0)),
PAR_FEC SMALLDATETIME,
PAR_POR DECIMAL(12,4) DEFAULT ((0)),
PAR_SIM CHAR(1) DEFAULT (','),
PAR_VER INT DEFAULT ((0))
 CONSTRAINT PK_PARAMETROS PRIMARY KEY CLUSTERED (PAR_ID))
CREATE TABLE TARIFAS ( 
TAR_ORI VARCHAR(8) NOT NULL,
TAR_DES VARCHAR(8) NOT NULL,
TAR_ANT MONEY DEFAULT ((0)),
TAR_VAL MONEY DEFAULT ((0)),
TAR_NCO VARCHAR(50),
TAR_NCD VARCHAR(50)
 CONSTRAINT PK_TARIFAS PRIMARY KEY CLUSTERED (TAR_ORI,TAR_DES),
 CONSTRAINT CK_TARIFASTAR_DES CHECK ((len([TAR_DES])>(0))),
 CONSTRAINT CK_TARIFASTAR_ORI CHECK ((len([TAR_ORI])>(0))))
CREATE TABLE TMPDED ( 
TMP_CDT VARCHAR(11) NOT NULL,
TMP_DEV VARCHAR(240),
TMP_DED VARCHAR(240)
 CONSTRAINT PK_TMPDED PRIMARY KEY CLUSTERED (TMP_CDT),
 CONSTRAINT CK_TMPDEDTMP_CDT CHECK ((len([TMP_CDT])>(0))))
CREATE TABLE TMPVIA ( 
TMP_CON VARCHAR(11) NOT NULL,
TMP_PLA INT DEFAULT ((0)) NOT NULL,
TMP_CIA CHAR(2) DEFAULT ('01') NOT NULL,
TMP_VEH VARCHAR(10),
TMP_FEC SMALLDATETIME,
TMP_CUM SMALLDATETIME,
TMP_ORI VARCHAR(8),
TMP_DES VARCHAR(8),
TMP_ANT MONEY DEFAULT ((0)),
TMP_VAL MONEY DEFAULT ((0)),
TMP_NCO VARCHAR(30),
TMP_NCD VARCHAR(30)
 CONSTRAINT PK_TMPVIA PRIMARY KEY CLUSTERED (TMP_CON,TMP_PLA,TMP_CIA),
 CONSTRAINT CK_TMPVIATMP_CIA CHECK ((len([TMP_CIA])>(0))),
 CONSTRAINT CK_TMPVIATMP_CON CHECK ((len([TMP_CON])>(0))))
CREATE TABLE USUARIOS ( 
USU_ID VARCHAR(8) NOT NULL,
USU_NOM VARCHAR(20) NOT NULL,
USU_PWD NVARCHAR(50)
 CONSTRAINT PK_USUARIOS PRIMARY KEY CLUSTERED (USU_ID),
 CONSTRAINT CK_USUARIOSUSU_ID CHECK ((len([USU_ID])>(0))),
 CONSTRAINT CK_USUARIOSUSU_NOM CHECK ((len([USU_NOM])>(0))))
CREATE TABLE VIAJES ( 
VIA_MES INT DEFAULT ((0)) NOT NULL,
VIA_ANO INT DEFAULT ((0)) NOT NULL,
VIA_PER INT DEFAULT ((0)) NOT NULL,
VIA_CON VARCHAR(11) NOT NULL,
VIA_NUM INT DEFAULT ((0)) NOT NULL,
VIA_CIA CHAR(2) DEFAULT ('01') NOT NULL,
VIA_FEC SMALLDATETIME,
VIA_ANT MONEY DEFAULT ((0)),
VIA_VAL MONEY DEFAULT ((0)),
VIA_TIP VARCHAR(3) DEFAULT ('PLT')
 CONSTRAINT PK_VIAJES PRIMARY KEY CLUSTERED (VIA_MES,VIA_ANO,VIA_PER,VIA_CON,VIA_NUM,VIA_CIA),
 CONSTRAINT CK_VIAJESVIA_CIA CHECK ((len([VIA_CIA])>(0))),
 CONSTRAINT CK_VIAJESVIA_CON CHECK ((len([VIA_CON])>(0))))
GO
 CREATE NONCLUSTERED INDEX IX_LIQUIDALIQ_PLA ON LIQUIDA(LIQ_PLA)
 CREATE NONCLUSTERED INDEX IX_LIQUIDALIQ_FEC ON LIQUIDA(LIQ_FEC)

GO
