USE [Database]

IF OBJECT_ID('[Functions].[does_barcode_exist]') IS NOT NULL
  DROP FUNCTION [Functions].[does_barcode_exist];
GO
CREATE FUNCTION [Functions].[does_barcode_exist](
  @barcode AS BIGINT
)
RETURNS BIT
AS
BEGIN
	IF EXISTS(
		SELECT *
		FROM [Tables].[products]
	    WHERE [barcode] = @barcode
	)
		RETURN CAST(1 AS BIT);
	RETURN CAST(0 AS BIT);
END
