CREATE TABLE tm_Cartera ( 
tmEst CHAR(2) NOT NULL,
TipDoc VARCHAR(3) DEFAULT ('FCR') NOT NULL,
Factura INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (1) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FechaVence SMALLDATETIME NOT NULL,
VrFactura MONEY DEFAULT (0) NOT NULL,
VrAbonado MONEY DEFAULT (0) NOT NULL,
VrSaldo MONEY DEFAULT (0) NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
IdVend VARCHAR(16) NOT NULL,
Comision DECIMAL(14,4) DEFAULT (0) NOT NULL,
TarifDcto DECIMAL(14,4) DEFAULT (0) NOT NULL,
TipoDcto CHAR(1) DEFAULT ('%'),
TipoBase VARCHAR(10) DEFAULT ('TOTAL'),
FecLmtDcto SMALLDATETIME,
IdConcepto VARCHAR(4) NOT NULL,
Referencia VARCHAR(50),
Detalle VARCHAR(150),
TipRef VARCHAR(3),
DocRef INT DEFAULT (0) NOT NULL,
IdCiaRef CHAR(2),
FecUltPago SMALLDATETIME,
NumNota INT DEFAULT (0) NOT NULL,
IdCiaNot CHAR(2),
TarifInt DECIMAL(14,4) DEFAULT (0) NOT NULL,
FecLiqMora SMALLDATETIME,
CtaForma VARCHAR(30) NOT NULL,
Beneficiario VARCHAR(150),
RefCheque VARCHAR(50),
NumCheque VARCHAR(20),
CdBanco VARCHAR(4)
 CONSTRAINT PK_tm_Cartera PRIMARY KEY CLUSTERED (tmEst,TipDoc,Factura,IdCia,Item),
 CONSTRAINT CK_tm_CarteraCtaForma CHECK ((len([CtaForma]) > 0)),
 CONSTRAINT CK_tm_CarteraIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_tm_CarteraIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_tm_CarteraIdCliente CHECK ((len([IdCliente]) > 0)),
 CONSTRAINT CK_tm_CarteraIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_tm_CarteraIdVend CHECK ((len([IdVend]) > 0)),
 CONSTRAINT CK_tm_CarteraTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_tm_CarteratmEst CHECK ((len([tmEst]) > 0)))
GO
 CREATE NONCLUSTERED INDEX IX_tm_CarteraFactura ON tm_Cartera(TipDoc,Factura,IdCia,Item)
 CREATE NONCLUSTERED INDEX IX_tm_CarteraFecha ON tm_Cartera(Fecha)
 CREATE NONCLUSTERED INDEX IX_tm_CarteraIdCliente ON tm_Cartera(IdCliente)
 CREATE NONCLUSTERED INDEX IX_tm_CarteraIdVend ON tm_Cartera(IdVend)
GO