CREATE TABLE LogDocTempTallas ( 
Id INT DEFAULT ((0)) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
ItemKdx INT DEFAULT ((0)) NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
IdCia CHAR(2) NOT NULL,
IdBodega VARCHAR(4) NOT NULL,
IdUbic VARCHAR(10),
NumTalla VARCHAR(30) NOT NULL,
Entradas DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
Salidas DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CdNueBod VARCHAR(4),
CdNueUbic VARCHAR(10)
 CONSTRAINT PK_LogDocTempTallas PRIMARY KEY CLUSTERED (Id,Item))
GO
CREATE TABLE LogTmConsDet ( 
Id INT IDENTITY ( 1,1 ) NOT NULL,
IdUsuario VARCHAR(5) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
TipPed VARCHAR(3) DEFAULT ('PED') NOT NULL,
Pedido INT DEFAULT ((0)) NOT NULL,
IdCiaPed CHAR(2) DEFAULT ('00') NOT NULL,
ItemPed INT DEFAULT ((0)) NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
IdBodega VARCHAR(4) NOT NULL,
CdUbic VARCHAR(10),
NumTalla VARCHAR(30) NOT NULL,
CantPedido DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CantAprob DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
Existencias DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CantSaldo DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CantTdo DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CdBodTdo VARCHAR(4) NOT NULL,
Tallas BIT DEFAULT ((0)) NOT NULL,
IdUnd VARCHAR(4) NOT NULL,
Descripcion VARCHAR(500),
Bodega VARCHAR(50),
Unidad VARCHAR(50),
BodegaTdo VARCHAR(50)
 CONSTRAINT PK_LogTmConsDet PRIMARY KEY NONCLUSTERED (Id),
 CONSTRAINT CK_LogTmConsDetCdBodTdo CHECK ((len([CdBodTdo])>(0))),
 CONSTRAINT CK_LogTmConsDetIdBodega CHECK ((len([IdBodega])>(0))),
 CONSTRAINT CK_LogTmConsDetIdCiaPed CHECK ((len([IdCiaPed])>(0))),
 CONSTRAINT CK_LogTmConsDetIdProducto CHECK ((len([IdProducto])>(0))),
 CONSTRAINT CK_LogTmConsDetIdUnd CHECK ((len([IdUnd])>(0))),
 CONSTRAINT CK_LogTmConsDetIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_LogTmConsDetNumTalla CHECK ((len([NumTalla])>(0))),
 CONSTRAINT CK_LogTmConsDetTipPed CHECK ((len([TipPed])>(0))))
GO
CREATE TABLE LogTmConsInsu ( 
Id INT IDENTITY ( 1,1 ) NOT NULL,
IdUsuario VARCHAR(5) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
TipPed VARCHAR(3) DEFAULT ('PED') NOT NULL,
Pedido INT DEFAULT ((0)) NOT NULL,
IdCiaPed CHAR(2) DEFAULT ('00') NOT NULL,
ItemPed INT DEFAULT ((0)) NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
IdInsumo VARCHAR(16) NOT NULL,
IdTipProc VARCHAR(4) NOT NULL,
IdBodega VARCHAR(4) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
Existencias DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CantSaldo DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CantTdo DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CantOrden DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CdBodTdo VARCHAR(4) NOT NULL,
Descripcion VARCHAR(500),
DescInsumo VARCHAR(500),
Bodega VARCHAR(50),
BodegaTdo VARCHAR(50),
Proceso VARCHAR(150),
CantPed DECIMAL(14,4) DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_LogTmConsInsu PRIMARY KEY NONCLUSTERED (Id),
 CONSTRAINT CK_LogTmConsInsuCdBodTdo CHECK ((len([CdBodTdo])>(0))),
 CONSTRAINT CK_LogTmConsInsuIdBodega CHECK ((len([IdBodega])>(0))),
 CONSTRAINT CK_LogTmConsInsuIdCiaPed CHECK ((len([IdCiaPed])>(0))),
 CONSTRAINT CK_LogTmConsInsuIdInsumo CHECK ((len([IdInsumo])>(0))),
 CONSTRAINT CK_LogTmConsInsuIdProducto CHECK ((len([IdProducto])>(0))),
 CONSTRAINT CK_LogTmConsInsuIdTipProc CHECK ((len([IdTipProc])>(0))),
 CONSTRAINT CK_LogTmConsInsuIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_LogTmConsInsuTipPed CHECK ((len([TipPed])>(0))))
GO
CREATE TABLE LogTmConsProc ( 
Id INT IDENTITY ( 1,1 ) NOT NULL,
IdUsuario VARCHAR(5) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
TipPed VARCHAR(3) DEFAULT ('PED') NOT NULL,
Pedido INT DEFAULT ((0)) NOT NULL,
IdCiaPed CHAR(2) DEFAULT ('00') NOT NULL,
ItemPed INT DEFAULT ((0)) NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
IdBodega VARCHAR(4) NOT NULL,
CdUbic VARCHAR(10),
NumTalla VARCHAR(30) NOT NULL,
CantAprob DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
Existencias DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CantSaldo DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CantTdo DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
IdTipProc VARCHAR(4) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
Tallas BIT DEFAULT ((0)) NOT NULL,
ProcFinal BIT DEFAULT ((0)) NOT NULL,
Descripcion VARCHAR(500),
Bodega VARCHAR(50),
Proceso VARCHAR(150)
 CONSTRAINT PK_LogTmConsProc PRIMARY KEY NONCLUSTERED (Id),
 CONSTRAINT CK_LogTmConsProcIdBodega CHECK ((len([IdBodega])>(0))),
 CONSTRAINT CK_LogTmConsProcIdCiaPed CHECK ((len([IdCiaPed])>(0))),
 CONSTRAINT CK_LogTmConsProcIdProducto CHECK ((len([IdProducto])>(0))),
 CONSTRAINT CK_LogTmConsProcIdTipProc CHECK ((len([IdTipProc])>(0))),
 CONSTRAINT CK_LogTmConsProcIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_LogTmConsProcNumTalla CHECK ((len([NumTalla])>(0))),
 CONSTRAINT CK_LogTmConsProcTipPed CHECK ((len([TipPed])>(0))))
GO
 CREATE CLUSTERED INDEX IX_LogTmConsDetIdUsuario ON LogTmConsDet(IdUsuario,Item)
 CREATE CLUSTERED INDEX IX_LogTmConsInsuIdUsuario ON LogTmConsInsu(IdUsuario,Item)
 CREATE CLUSTERED INDEX IX_LogTmConsProcIdUsuario ON LogTmConsProc(IdUsuario,Item)

