IF COL_LENGTH('Clientes_Invitados_Mov', 'Id_ES') IS NULL 
	ALTER TABLE Clientes_Invitados_Mov ADD Id_ES INT
GO

IF IndexProperty(Object_Id('Clientes_Invitados_Mov'), 'IX_CLIIM_PorES', 'IndexID') IS NULL
	CREATE INDEX IX_CLIIM_PorES ON Clientes_Invitados_Mov (Id_ES)
GO 

IF EXISTS (SELECT * FROM sysobjects WHERE Name='Clientes_Invitados_Mov' AND xtype='U')
	AND NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE CONSTRAINT_TYPE = 'FOREIGN KEY' 
	AND CONSTRAINT_NAME = 'FK_CLIIM_ES')
BEGIN
	ALTER TABLE Clientes_Invitados_Mov  ADD CONSTRAINT FK_CLIIM_ES FOREIGN KEY(Id_ES)
	REFERENCES CD_ES (Id_ES)
END
GO

