ALTER TABLE Terceros ADD IdEstOper VARCHAR(4),IdLocUbic VARCHAR(8),DescUbicac VARCHAR(150)
GO
ALTER TABLE Trn_NomConAuto ADD NitTercero VARCHAR(16)
GO
ALTER TABLE tm_Nomina ADD tmNitTercero VARCHAR(16)
GO
ALTER TABLE Trn_NomDetalle ADD NitTercero VARCHAR(16)
GO
ALTER TABLE tm_Liquida ADD tmNitTercero VARCHAR(16)
GO
ALTER TABLE Trn_NomLiqDet ADD NitTercero VARCHAR(16)
GO
ALTER TABLE TercCuentas ADD NitTercAut VARCHAR(16)
GO
ALTER TABLE Trn_ReqDetalle ADD Referencia VARCHAR(250)
GO
CREATE TABLE EstadoOper ( 
IdEstado VARCHAR(4) NOT NULL,
Estado VARCHAR(50) NOT NULL,
NColor INT DEFAULT ((0)) NOT NULL,
Inactivo BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_EstadoOper PRIMARY KEY CLUSTERED (IdEstado),
 CONSTRAINT CK_EstadoOperEstado CHECK ((len([Estado])>(0))))
GO
CREATE TABLE Trn_TraOrdenOper ( 
TipDoc VARCHAR(3) NOT NULL,
NumOrden INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdOperario VARCHAR(16) NOT NULL
 CONSTRAINT PK_Trn_TraOrdenOper PRIMARY KEY CLUSTERED (TipDoc,NumOrden,IdCia,Item),
 CONSTRAINT CK_Trn_TraOrdenOperIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_TraOrdenOperIdOperario CHECK ((len([IdOperario])>(0))),
 CONSTRAINT CK_Trn_TraOrdenOperTipDoc CHECK ((len([TipDoc])>(0))))
GO
CREATE TABLE tm_TraOperarios ( 
Id VARCHAR(5) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdTercero VARCHAR(16) NOT NULL,
RazonSocial VARCHAR(250)
 CONSTRAINT PK_tm_TraOperarios PRIMARY KEY CLUSTERED (Id,Item),
 CONSTRAINT CK_tm_TraOperariosId CHECK ((len([Id])>(0))),
 CONSTRAINT CK_tm_TraOperariosIdTercero CHECK ((len([IdTercero])>(0))))
GO
CREATE TABLE tm_TraInfOper ( 
Id BIGINT IDENTITY ( 1,1 ) NOT NULL,
IdEst CHAR(2) NOT NULL,
TipoRep INT DEFAULT ((0)) NOT NULL,
IdOperario VARCHAR(16) NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
nRemolque VARCHAR(10),
TipoOrd VARCHAR(3) NOT NULL,
NumOrden INT DEFAULT ((0)) NOT NULL,
IdCiaOrd CHAR(2),
Remesa INT DEFAULT ((0)) NOT NULL,
IdCiaRem CHAR(2)
 CONSTRAINT PK_tm_TraInfOper PRIMARY KEY NONCLUSTERED (Id),
 CONSTRAINT CK_tm_TraInfOperIdEst CHECK ((len([IdEst])>(0))),
 CONSTRAINT CK_tm_TraInfOperIdOperario CHECK ((len([IdOperario])>(0))),
 CONSTRAINT CK_tm_TraInfOperIdVehiculo CHECK ((len([IdVehiculo])>(0))),
 CONSTRAINT CK_tm_TraInfOperTipoOrd CHECK ((len([TipoOrd])>(0))))
GO
ALTER TABLE Trn_TraOrdenOper ADD 
 CONSTRAINT FK_Trn_TraOrdenOper_Terceros FOREIGN KEY (IdOperario) REFERENCES [dbo].[Terceros] (IdTercero)

CREATE CLUSTERED INDEX IX_tm_TraInfOperIdVehiculo ON tm_TraInfOper(IdEst,IdOperario,IdVehiculo)
