ALTER TABLE ENTRADAS ADD ENT_TDS VARCHAR(3),ENT_NDS INT DEFAULT(0),ENT_CDS CHAR(2)
GO
ALTER TABLE DETLEG ADD DET_TDS VARCHAR(3),DET_NDS INT DEFAULT(0),DET_CDS CHAR(2)
GO
ALTER TABLE PLANILLAS ADD PLA_TKT MONEY DEFAULT(0),PLA_EXC MONEY DEFAULT(0),PLA_DCT MONEY DEFAULT(0)
GO
ALTER TABLE DEVOLUCIONES ADD DEV_TKT MONEY DEFAULT(0),DEV_EXC MONEY DEFAULT(0),DEV_DVC MONEY DEFAULT(0)
GO
ALTER TABLE PAGOS ADD PAG_TKT BIT DEFAULT(0),PAG_PRE MONEY DEFAULT(0),PAG_BAS MONEY DEFAULT(0),PAG_PEC MONEY DEFAULT(0)
GO
CREATE TABLE DOCSOPORTE ( 
SOP_TIP VARCHAR(3) NOT NULL,
SOP_NUM INT DEFAULT ((0)) NOT NULL,
SOP_CIA CHAR(2) NOT NULL,
SOP_FEC SMALLDATETIME NOT NULL,
SOP_NIT VARCHAR(11) NOT NULL,
SOP_ADQ VARCHAR(11),
SOP_VAL DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
SOP_RET DECIMAL(14,4) DEFAULT ((0)),
SOP_ICA DECIMAL(14,4) DEFAULT ((0)),
SOP_DCS VARCHAR(250),
SOP_RES VARCHAR(3),
SOP_TDR VARCHAR(3) NOT NULL,
SOP_NDR INT DEFAULT ((0)) NOT NULL,
SOP_CDR CHAR(2) NOT NULL,
SOP_TDD VARCHAR(3),
SOP_NDD INT DEFAULT ((0)) NOT NULL,
SOP_CDD CHAR(2)
 CONSTRAINT PK_DOCSOPORTE PRIMARY KEY CLUSTERED (SOP_TIP,SOP_NUM,SOP_CIA),
 CONSTRAINT CK_DOCSOPORTESOP_CDR CHECK ((len([SOP_CDR])>(0))),
 CONSTRAINT CK_DOCSOPORTESOP_CIA CHECK ((len([SOP_CIA])>(0))),
 CONSTRAINT CK_DOCSOPORTESOP_NIT CHECK ((len([SOP_NIT])>(0))),
 CONSTRAINT CK_DOCSOPORTESOP_TDR CHECK ((len([SOP_TDR])>(0))),
 CONSTRAINT CK_DOCSOPORTESOP_TIP CHECK ((len([SOP_TIP])>(0))))
CREATE TABLE DOCSOPORTEDET ( 
DET_TIP VARCHAR(3) NOT NULL,
DET_NUM INT DEFAULT ((0)) NOT NULL,
DET_CIA CHAR(2) NOT NULL,
DET_ITM INT DEFAULT ((0)) NOT NULL,
DET_TCO VARCHAR(3) NOT NULL,
DET_NCO INT DEFAULT ((0)) NOT NULL,
DET_CCO CHAR(2) NOT NULL,
DET_ICO INT DEFAULT ((0)) NOT NULL,
DET_CUE VARCHAR(16) NOT NULL,
DET_DES VARCHAR(250) NOT NULL,
DET_NIT VARCHAR(11) NOT NULL,
DET_VAL DECIMAL(14,4) DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_DOCSOPORTEDET PRIMARY KEY CLUSTERED (DET_TIP,DET_NUM,DET_CIA,DET_ITM),
 CONSTRAINT CK_DOCSOPORTEDETDET_CCO CHECK ((len([DET_CCO])>(0))),
 CONSTRAINT CK_DOCSOPORTEDETDET_CIA CHECK ((len([DET_CIA])>(0))),
 CONSTRAINT CK_DOCSOPORTEDETDET_CUE CHECK ((len([DET_CUE])>(0))),
 CONSTRAINT CK_DOCSOPORTEDETDET_DES CHECK ((len([DET_DES])>(0))),
 CONSTRAINT CK_DOCSOPORTEDETDET_NIT CHECK ((len([DET_NIT])>(0))),
 CONSTRAINT CK_DOCSOPORTEDETDET_TCO CHECK ((len([DET_TCO])>(0))),
 CONSTRAINT CK_DOCSOPORTEDETDET_TIP CHECK ((len([DET_TIP])>(0))))
GO
 CREATE NONCLUSTERED INDEX IX_DOCSOPORTESOP_NDR ON DOCSOPORTE(SOP_TDR,SOP_NDR,SOP_CDR)
 CREATE NONCLUSTERED INDEX IX_DOCSOPORTESOP_FEC ON DOCSOPORTE(SOP_FEC)
 CREATE NONCLUSTERED INDEX IX_DOCSOPORTEDETDET_NCO ON DOCSOPORTEDET(DET_TCO,DET_NCO,DET_CCO)

