CREATE TABLE Trn_TraPorteInt ( 
TipDoc VARCHAR(3) DEFAULT ('CPI') NOT NULL,
NumOrden INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FecEmision SMALLDATETIME NOT NULL,
FecCargue SMALLDATETIME NOT NULL,
FecEntrega SMALLDATETIME,
IdOrigen VARCHAR(8) NOT NULL,
IdDestino VARCHAR(8) NOT NULL,
IdNotificado VARCHAR(16) NOT NULL,
Notificado VARCHAR(150) NOT NULL,
IdRemitente VARCHAR(16) NOT NULL,
Remitente VARCHAR(150) NOT NULL,
DirOrigen VARCHAR(250),
IdDestinatario VARCHAR(16) NOT NULL,
Destinatario VARCHAR(150) NOT NULL,
DirDestino VARCHAR(250),
IdConsig VARCHAR(16) NOT NULL,
Consignatario VARCHAR(150),
DirConsig VARCHAR(250),
InsTransporte VARCHAR(1000),
DocRemitente VARCHAR(500),
IdMoneda VARCHAR(5) NOT NULL,
ValorTotal MONEY DEFAULT ((0)) NOT NULL,
PesoTotal DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
Manifiesto INT DEFAULT ((0)) NOT NULL,
CdCiaManif CHAR(2),
OrigenAdd VARCHAR(10) NOT NULL,
Anulado BIT DEFAULT ((0)) NOT NULL,
FecDev SMALLDATETIME,
Observacion VARCHAR(2500),
IdEstado VARCHAR(4) NOT NULL,
TimeSys SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdCiaCrea CHAR(2) DEFAULT ('01') NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_TraPorteInt PRIMARY KEY CLUSTERED (TipDoc,NumOrden,IdCia),
 CONSTRAINT CK_Trn_TraPorteIntDestinatario CHECK ((len([Destinatario])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntIdConsig CHECK ((len([IdConsig])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntIdDestinatario CHECK ((len([IdDestinatario])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntIdDestino CHECK ((len([IdDestino])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntIdMoneda CHECK ((len([IdMoneda])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntIdNotificado CHECK ((len([IdNotificado])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntIdOrigen CHECK ((len([IdOrigen])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntIdRemitente CHECK ((len([IdRemitente])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntNotificado CHECK ((len([Notificado])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntRemitente CHECK ((len([Remitente])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_TraPorteIntGas ( 
TipDoc VARCHAR(3) DEFAULT ('CPI') NOT NULL,
NumOrden INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
MontoRem MONEY DEFAULT ((0)) NOT NULL,
IdMonRem VARCHAR(4) NOT NULL,
MontoDest MONEY DEFAULT ((0)) NOT NULL,
IdMonDest VARCHAR(4) NOT NULL
 CONSTRAINT PK_Trn_TraPorteIntGas PRIMARY KEY CLUSTERED (TipDoc,NumOrden,IdCia,Item),
 CONSTRAINT CK_Trn_TraPorteIntGasIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntGasIdConcepto CHECK ((len([IdConcepto])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntGasIdMonDest CHECK ((len([IdMonDest])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntGasIdMonRem CHECK ((len([IdMonRem])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntGasTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_TraPorteIntMcia ( 
TipDoc VARCHAR(3) DEFAULT ('CPI') NOT NULL,
NumOrden INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
CdMercancia VARCHAR(16) NOT NULL,
DescripMcias VARCHAR(500) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
PesoNeto DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
PesoBruto DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
Volumen DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
ValorMcia MONEY DEFAULT ((0)) NOT NULL,
IdMoneda VARCHAR(5) NOT NULL,
IdUnd VARCHAR(4) NOT NULL,
IdEmp VARCHAR(4) NOT NULL,
IdNat VARCHAR(4) NOT NULL,
UndMed VARCHAR(10) NOT NULL,
UndVol VARCHAR(10),
Bultos VARCHAR(150),
Observacion VARCHAR(1000)
 CONSTRAINT PK_Trn_TraPorteIntMcia PRIMARY KEY CLUSTERED (TipDoc,NumOrden,IdCia,Item),
 CONSTRAINT CK_Trn_TraPorteIntMciaCdMercancia CHECK ((len([CdMercancia])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntMciaDescripMcias CHECK ((len([DescripMcias])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntMciaIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntMciaIdEmp CHECK ((len([IdEmp])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntMciaIdMoneda CHECK ((len([IdMoneda])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntMciaIdNat CHECK ((len([IdNat])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntMciaIdUnd CHECK ((len([IdUnd])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntMciaTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntMciaUndMed CHECK ((len([UndMed])>(0))))
CREATE TABLE Trn_TraManifInt ( 
TipDoc VARCHAR(3) DEFAULT ('MCI') NOT NULL,
Manifiesto INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FecEmision SMALLDATETIME NOT NULL,
IdOrigen VARCHAR(8) NOT NULL,
IdDestino VARCHAR(8) NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
nRemolque VARCHAR(10),
IdConductor VARCHAR(16) NOT NULL,
IdCondRelev VARCHAR(16),
NatCarga VARCHAR(50),
CdAduana VARCHAR(4),
CdAduanaDest VARCHAR(4),
IdMoneda VARCHAR(5) NOT NULL,
ValorTotal MONEY DEFAULT ((0)) NOT NULL,
PesoTotal DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
NumMuc INT DEFAULT ((0)) NOT NULL,
CdCiaMuc CHAR(2) NOT NULL,
OrigenAdd VARCHAR(10) NOT NULL,
Anulado BIT DEFAULT ((0)) NOT NULL,
FecDev SMALLDATETIME,
Observacion VARCHAR(2500),
IdEstado VARCHAR(4) NOT NULL,
TimeSys SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdCiaCrea CHAR(2) DEFAULT ('01') NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_TraManifInt PRIMARY KEY CLUSTERED (TipDoc,Manifiesto,IdCia),
 CONSTRAINT CK_Trn_TraManifIntCdCiaMuc CHECK ((len([CdCiaMuc])>(0))),
 CONSTRAINT CK_Trn_TraManifIntIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_TraManifIntIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_TraManifIntIdConductor CHECK ((len([IdConductor])>(0))),
 CONSTRAINT CK_Trn_TraManifIntIdDestino CHECK ((len([IdDestino])>(0))),
 CONSTRAINT CK_Trn_TraManifIntIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_TraManifIntIdMoneda CHECK ((len([IdMoneda])>(0))),
 CONSTRAINT CK_Trn_TraManifIntIdOrigen CHECK ((len([IdOrigen])>(0))),
 CONSTRAINT CK_Trn_TraManifIntIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_TraManifIntIdVehiculo CHECK ((len([IdVehiculo])>(0))),
 CONSTRAINT CK_Trn_TraManifIntOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_TraManifIntTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_TraManifIntCon ( 
TipDoc VARCHAR(3) DEFAULT ('MCI') NOT NULL,
Manifiesto INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdTipoCon VARCHAR(4) NOT NULL,
NumCont VARCHAR(50) NOT NULL,
PesoCont DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
IdTipoPre VARCHAR(4) NOT NULL,
NumPrecinto VARCHAR(50) NOT NULL,
ColorPrecinto VARCHAR(50) NOT NULL
 CONSTRAINT PK_Trn_TraManifIntCon PRIMARY KEY CLUSTERED (TipDoc,Manifiesto,IdCia,Item),
 CONSTRAINT CK_Trn_TraManifIntConColorPrecinto CHECK ((len([ColorPrecinto])>(0))),
 CONSTRAINT CK_Trn_TraManifIntConIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_TraManifIntConIdTipoCon CHECK ((len([IdTipoCon])>(0))),
 CONSTRAINT CK_Trn_TraManifIntConIdTipoPre CHECK ((len([IdTipoPre])>(0))),
 CONSTRAINT CK_Trn_TraManifIntConNumCont CHECK ((len([NumCont])>(0))),
 CONSTRAINT CK_Trn_TraManifIntConNumPrecinto CHECK ((len([NumPrecinto])>(0))),
 CONSTRAINT CK_Trn_TraManifIntConTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_TraManifIntMcia ( 
TipDoc VARCHAR(3) DEFAULT ('MCI') NOT NULL,
Manifiesto INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
TipOrd VARCHAR(3) DEFAULT ('CPI') NOT NULL,
NumOrden INT DEFAULT ((0)) NOT NULL,
IdCiaOrd CHAR(2) NOT NULL,
CdMercancia VARCHAR(16) NOT NULL,
DescripMcias VARCHAR(500) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
PesoNeto DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
PesoBruto DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
Volumen DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
ValorMcia MONEY DEFAULT ((0)) NOT NULL,
IdMoneda VARCHAR(5) NOT NULL,
IdUnd VARCHAR(4) NOT NULL,
IdEmp VARCHAR(4) NOT NULL,
IdNat VARCHAR(4) NOT NULL,
UndMed VARCHAR(10) NOT NULL,
UndVol VARCHAR(10),
Bultos VARCHAR(150)
 CONSTRAINT PK_Trn_TraManifIntMcia PRIMARY KEY CLUSTERED (TipDoc,Manifiesto,IdCia,Item),
 CONSTRAINT CK_Trn_TraManifIntMciaCdMercancia CHECK ((len([CdMercancia])>(0))),
 CONSTRAINT CK_Trn_TraManifIntMciaDescripMcias CHECK ((len([DescripMcias])>(0))),
 CONSTRAINT CK_Trn_TraManifIntMciaIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_TraManifIntMciaIdCiaOrd CHECK ((len([IdCiaOrd])>(0))),
 CONSTRAINT CK_Trn_TraManifIntMciaIdEmp CHECK ((len([IdEmp])>(0))),
 CONSTRAINT CK_Trn_TraManifIntMciaIdMoneda CHECK ((len([IdMoneda])>(0))),
 CONSTRAINT CK_Trn_TraManifIntMciaIdNat CHECK ((len([IdNat])>(0))),
 CONSTRAINT CK_Trn_TraManifIntMciaIdUnd CHECK ((len([IdUnd])>(0))),
 CONSTRAINT CK_Trn_TraManifIntMciaTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_TraManifIntMciaTipOrd CHECK ((len([TipOrd])>(0))),
 CONSTRAINT CK_Trn_TraManifIntMciaUndMed CHECK ((len([UndMed])>(0))))
CREATE TABLE Trn_TraDecAduana ( 
TipDoc VARCHAR(3) DEFAULT ('DTA') NOT NULL,
NumDeclara INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FecEmision SMALLDATETIME NOT NULL,
IdOrigen VARCHAR(8) NOT NULL,
IdAduCarga VARCHAR(4) NOT NULL,
IdDestino VARCHAR(8) NOT NULL,
IdAduOrigen VARCHAR(4) NOT NULL,
IdAduDestino VARCHAR(4) NOT NULL,
IdAduFrontera VARCHAR(4),
IdDeclarante VARCHAR(16) NOT NULL,
Declarante VARCHAR(150) NOT NULL,
DirDeclara VARCHAR(250),
CdLocalDec VARCHAR(8),
IdRemitente VARCHAR(16) NOT NULL,
Remitente VARCHAR(150) NOT NULL,
DirOrigen VARCHAR(250),
CdLocalRem VARCHAR(8),
IdDestinatario VARCHAR(16) NOT NULL,
Destinatario VARCHAR(150) NOT NULL,
DirDestino VARCHAR(250),
CdLocalDest VARCHAR(8),
IdConsig VARCHAR(16) NOT NULL,
Consignatario VARCHAR(150),
DirConsig VARCHAR(250),
CdLocalConsig VARCHAR(8),
IdMoneda VARCHAR(5) NOT NULL,
ValorTotal MONEY DEFAULT ((0)) NOT NULL,
PesoTotal DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
DocAnexos VARCHAR(500),
Vehiculos VARCHAR(250),
Remolques VARCHAR(250),
Manifiestos VARCHAR(100),
Contenedores VARCHAR(500),
Precintos VARCHAR(250),
OrigenAdd VARCHAR(10) NOT NULL,
Anulado BIT DEFAULT ((0)) NOT NULL,
FecDev SMALLDATETIME,
Observacion VARCHAR(2500),
IdEstado VARCHAR(4) NOT NULL,
TimeSys SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdCiaCrea CHAR(2) DEFAULT ('01') NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_TraDecAduana PRIMARY KEY CLUSTERED (TipDoc,NumDeclara,IdCia),
 CONSTRAINT CK_Trn_TraDecAduanaDeclarante CHECK ((len([Declarante])>(0))),
 CONSTRAINT CK_Trn_TraDecAduanaDestinatario CHECK ((len([Destinatario])>(0))),
 CONSTRAINT CK_Trn_TraDecAduanaIdAduCarga CHECK ((len([IdAduCarga])>(0))),
 CONSTRAINT CK_Trn_TraDecAduanaIdAduDestino CHECK ((len([IdAduDestino])>(0))),
 CONSTRAINT CK_Trn_TraDecAduanaIdAduOrigen CHECK ((len([IdAduOrigen])>(0))),
 CONSTRAINT CK_Trn_TraDecAduanaIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_TraDecAduanaIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_TraDecAduanaIdConsig CHECK ((len([IdConsig])>(0))),
 CONSTRAINT CK_Trn_TraDecAduanaIdDeclarante CHECK ((len([IdDeclarante])>(0))),
 CONSTRAINT CK_Trn_TraDecAduanaIdDestinatario CHECK ((len([IdDestinatario])>(0))),
 CONSTRAINT CK_Trn_TraDecAduanaIdDestino CHECK ((len([IdDestino])>(0))),
 CONSTRAINT CK_Trn_TraDecAduanaIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_TraDecAduanaIdMoneda CHECK ((len([IdMoneda])>(0))),
 CONSTRAINT CK_Trn_TraDecAduanaIdOrigen CHECK ((len([IdOrigen])>(0))),
 CONSTRAINT CK_Trn_TraDecAduanaIdRemitente CHECK ((len([IdRemitente])>(0))),
 CONSTRAINT CK_Trn_TraDecAduanaIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_TraDecAduanaOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_TraDecAduanaRemitente CHECK ((len([Remitente])>(0))),
 CONSTRAINT CK_Trn_TraDecAduanaTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_TraDecMcia ( 
TipDoc VARCHAR(3) NOT NULL,
NumDeclara INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
TipOrd VARCHAR(3) DEFAULT ('CPI') NOT NULL,
NumOrden INT DEFAULT ((0)) NOT NULL,
IdCiaOrd CHAR(2) NOT NULL,
CdMercancia VARCHAR(16) NOT NULL,
DescripMcias VARCHAR(500) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
PesoNeto DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
PesoBruto DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
Volumen DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
ValorMcia MONEY DEFAULT ((0)) NOT NULL,
IdMoneda VARCHAR(5) NOT NULL,
IdUnd VARCHAR(4) NOT NULL,
IdEmp VARCHAR(4) NOT NULL,
IdNat VARCHAR(4) NOT NULL,
UndMed VARCHAR(10) NOT NULL,
UndVol VARCHAR(10),
Bultos VARCHAR(150)
 CONSTRAINT PK_Trn_TraDecMcia PRIMARY KEY CLUSTERED (TipDoc,NumDeclara,IdCia,Item),
 CONSTRAINT CK_Trn_TraDecMciaCdMercancia CHECK ((len([CdMercancia])>(0))),
 CONSTRAINT CK_Trn_TraDecMciaDescripMcias CHECK ((len([DescripMcias])>(0))),
 CONSTRAINT CK_Trn_TraDecMciaIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_TraDecMciaIdCiaOrd CHECK ((len([IdCiaOrd])>(0))),
 CONSTRAINT CK_Trn_TraDecMciaIdEmp CHECK ((len([IdEmp])>(0))),
 CONSTRAINT CK_Trn_TraDecMciaIdMoneda CHECK ((len([IdMoneda])>(0))),
 CONSTRAINT CK_Trn_TraDecMciaIdNat CHECK ((len([IdNat])>(0))),
 CONSTRAINT CK_Trn_TraDecMciaIdUnd CHECK ((len([IdUnd])>(0))),
 CONSTRAINT CK_Trn_TraDecMciaTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_TraDecMciaTipOrd CHECK ((len([TipOrd])>(0))),
 CONSTRAINT CK_Trn_TraDecMciaUndMed CHECK ((len([UndMed])>(0))))
CREATE TABLE Aduanas ( 
IdAduana VARCHAR(4) NOT NULL,
NomAduana VARCHAR(150) NOT NULL,
IdPais VARCHAR(8) NOT NULL,
Inactivo BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Aduanas PRIMARY KEY CLUSTERED (IdAduana),
 CONSTRAINT CK_AduanasIdAduana CHECK ((len([IdAduana])>(0))),
 CONSTRAINT CK_AduanasIdPais CHECK ((len([IdPais])>(0))),
 CONSTRAINT CK_AduanasNomAduana CHECK ((len([NomAduana])>(0))))
GO
ALTER TABLE Trn_TraPorteInt ADD 
 CONSTRAINT FK_Trn_TraPorteInt_adm_monedas FOREIGN KEY (IdMoneda) REFERENCES [dbo].[adm_monedas] (IdMneda),
 CONSTRAINT FK_Trn_TraPorteInt_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_TraPorteInt_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraPorteInt_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraPorteInt_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_TraPorteInt_Localidades FOREIGN KEY (IdOrigen) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_TraPorteInt_Localidades1 FOREIGN KEY (IdDestino) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_TraPorteInt_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc)
 CREATE NONCLUSTERED INDEX IX_Trn_TraPorteIntFecha ON Trn_TraPorteInt(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_TraPorteIntFecEmision ON Trn_TraPorteInt(FecEmision)
 CREATE NONCLUSTERED INDEX IX_Trn_TraPorteIntIdOrigen ON Trn_TraPorteInt(IdOrigen,IdDestino)
ALTER TABLE Trn_TraPorteIntGas ADD 
 CONSTRAINT FK_Trn_TraPorteIntGas_ConcDiversos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[ConcDiversos] (IdConcepto),
 CONSTRAINT FK_Trn_TraPorteIntGas_Trn_TraPorteInt FOREIGN KEY (TipDoc,NumOrden,IdCia) REFERENCES [dbo].[Trn_TraPorteInt] (TipDoc,NumOrden,IdCia)
ALTER TABLE Trn_TraPorteIntMcia ADD 
 CONSTRAINT FK_Trn_TraPorteIntMcia_adm_monedas FOREIGN KEY (IdMoneda) REFERENCES [dbo].[adm_monedas] (IdMneda),
 CONSTRAINT FK_Trn_TraPorteIntMcia_TiposNat FOREIGN KEY (IdNat) REFERENCES [dbo].[TiposNat] (IdNat),
 CONSTRAINT FK_Trn_TraPorteIntMcia_Trn_TraPorteInt FOREIGN KEY (TipDoc,NumOrden,IdCia) REFERENCES [dbo].[Trn_TraPorteInt] (TipDoc,NumOrden,IdCia),
 CONSTRAINT FK_Trn_TraPorteIntMcia_UndMed FOREIGN KEY (IdUnd) REFERENCES [dbo].[UndMed] (IdUnd)

ALTER TABLE Trn_TraManifInt ADD 
 CONSTRAINT FK_Trn_TraManifInt_adm_monedas FOREIGN KEY (IdMoneda) REFERENCES [dbo].[adm_monedas] (IdMneda),
 CONSTRAINT FK_Trn_TraManifInt_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_TraManifInt_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraManifInt_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraManifInt_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_TraManifInt_Localidades FOREIGN KEY (IdOrigen) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_TraManifInt_Localidades1 FOREIGN KEY (IdDestino) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_TraManifInt_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_TraManifInt_Terceros FOREIGN KEY (IdConductor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_TraManifInt_Terceros1 FOREIGN KEY (IdCondRelev) REFERENCES [dbo].[Terceros] (IdTercero)

 CREATE NONCLUSTERED INDEX IX_Trn_TraManifIntFecha ON Trn_TraManifInt(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_TraManifIntFecEmision ON Trn_TraManifInt(FecEmision)
 CREATE NONCLUSTERED INDEX IX_Trn_TraManifIntIdOrigen ON Trn_TraManifInt(IdOrigen,IdDestino)
 CREATE NONCLUSTERED INDEX IX_Trn_TraManifIntIdVehiculo ON Trn_TraManifInt(IdVehiculo)
ALTER TABLE Trn_TraManifIntCon ADD 
 CONSTRAINT FK_Trn_TraManifIntCon_TiposCnd FOREIGN KEY (IdTipoCon) REFERENCES [dbo].[TiposCnd] (IdTipoCon),
 CONSTRAINT FK_Trn_TraManifIntCon_TiposPcnto FOREIGN KEY (IdTipoPre) REFERENCES [dbo].[TiposPcnto] (IdTipoPre),
 CONSTRAINT FK_Trn_TraManifIntCon_Trn_TraManifInt FOREIGN KEY (TipDoc,Manifiesto,IdCia) REFERENCES [dbo].[Trn_TraManifInt] (TipDoc,Manifiesto,IdCia)
ALTER TABLE Trn_TraManifIntMcia ADD 
 CONSTRAINT FK_Trn_TraManifIntMcia_adm_monedas FOREIGN KEY (IdMoneda) REFERENCES [dbo].[adm_monedas] (IdMneda),
 CONSTRAINT FK_Trn_TraManifIntMcia_TiposNat FOREIGN KEY (IdNat) REFERENCES [dbo].[TiposNat] (IdNat),
 CONSTRAINT FK_Trn_TraManifIntMcia_Trn_TraManifInt FOREIGN KEY (TipDoc,Manifiesto,IdCia) REFERENCES [dbo].[Trn_TraManifInt] (TipDoc,Manifiesto,IdCia),
 CONSTRAINT FK_Trn_TraManifIntMcia_UndMed FOREIGN KEY (IdUnd) REFERENCES [dbo].[UndMed] (IdUnd)
 CREATE NONCLUSTERED INDEX IX_Trn_TraManifIntMciaNumOrden ON Trn_TraManifIntMcia(TipOrd,NumOrden,IdCiaOrd)

ALTER TABLE Trn_TraDecAduana ADD 
 CONSTRAINT FK_Trn_TraDecAduana_adm_monedas FOREIGN KEY (IdMoneda) REFERENCES [dbo].[adm_monedas] (IdMneda),
 CONSTRAINT FK_Trn_TraDecAduana_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_TraDecAduana_Aduanas FOREIGN KEY (IdAduOrigen) REFERENCES [dbo].[Aduanas] (IdAduana),
 CONSTRAINT FK_Trn_TraDecAduana_Aduanas1 FOREIGN KEY (IdAduDestino) REFERENCES [dbo].[Aduanas] (IdAduana),
 CONSTRAINT FK_Trn_TraDecAduana_Aduanas2 FOREIGN KEY (IdAduCarga) REFERENCES [dbo].[Aduanas] (IdAduana),
 CONSTRAINT FK_Trn_TraDecAduana_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraDecAduana_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraDecAduana_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_TraDecAduana_Localidades FOREIGN KEY (IdOrigen) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_TraDecAduana_Localidades1 FOREIGN KEY (IdDestino) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_TraDecAduana_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc)
 CREATE NONCLUSTERED INDEX IX_Trn_TraDecAduanaFecha ON Trn_TraDecAduana(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_TraDecAduanaFecEmision ON Trn_TraDecAduana(FecEmision)
 CREATE NONCLUSTERED INDEX IX_Trn_TraDecAduanaIdDestino ON Trn_TraDecAduana(IdOrigen,IdDestino)
ALTER TABLE Trn_TraDecMcia ADD 
 CONSTRAINT FK_Trn_TraDecMcia_adm_monedas FOREIGN KEY (IdMoneda) REFERENCES [dbo].[adm_monedas] (IdMneda),
 CONSTRAINT FK_Trn_TraDecMcia_Trn_TraDecAduana FOREIGN KEY (TipDoc,NumDeclara,IdCia) REFERENCES [dbo].[Trn_TraDecAduana] (TipDoc,NumDeclara,IdCia),
 CONSTRAINT FK_Trn_TraDecMcia_UndMed FOREIGN KEY (IdUnd) REFERENCES [dbo].[UndMed] (IdUnd)
 CREATE NONCLUSTERED INDEX IX_Trn_TraDecMciaNumOrden ON Trn_TraDecMcia(TipOrd,NumOrden,IdCiaOrd)

ALTER TABLE Aduanas ADD 
 CONSTRAINT FK_Aduanas_adm_Paises FOREIGN KEY (IdPais) REFERENCES [dbo].[adm_Paises] (IdPais)
