CREATE FUNCTION dbo.getProductCurrencyCode(@ProductNumber int)
RETURNS int
AS
BEGIN
    DECLARE @r int
    SELECT @r = ProductCurrencyCode FROM ProductExtended WITH (NOLOCK) WHERE FK_ProductNumber = @ProductNumber
    RETURN @r
END
GO

IF EXISTS(SELECT * FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS WHERE CONSTRAINT_NAME ='FK_Products_Countries')
  ALTER TABLE dbo.Products DROP CONSTRAINT FK_Products_Countries


IF EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'CurrencyNumber'
    WHERE SysObjects.Name = 'Products'
)
  ALTER TABLE dbo.Products DROP COLUMN CurrencyNumber

ALTER TABLE dbo.Products ADD CurrencyNumber AS dbo.GetProductCurrencyCode([ProductNumber])