IF NOT EXISTS (SELECT * FROM sysobjects WHERE Name='Cbtes_Doc' AND xtype='U')
BEGIN
	CREATE TABLE Cbtes_Doc 
	(
		Id_Trans	INT NOT NULL,
		Item		SMALLINT NOT NULL,
		Descripcion VARCHAR(100),
		Fecha		DATETIME,
		Extension	VARCHAR(20),
		Documento	VARBINARY(MAX)
	)
END
GO

IF EXISTS (SELECT * FROM sysobjects WHERE Name='Cbtes_Doc' AND xtype='U')
BEGIN
	ALTER TABLE Cbtes_Doc ADD CONSTRAINT PK_CBTD_PorId PRIMARY KEY CLUSTERED (Id_Trans, Item)	
END
GO

IF EXISTS (SELECT * FROM sysobjects WHERE Name='Cbtes_Doc' AND xtype='U')
BEGIN
	ALTER TABLE Cbtes_Doc ADD CONSTRAINT FK_CBTD_Cbtes FOREIGN KEY (Id_Trans)
	REFERENCES Cbtes (Id_Trans)
END
GO