SQL

we should use real table but we will use temporary table at this time for the sake of testing.

declare @items table (field1 varchar(50), field2 varchar(50))
INSERT INTO @items (field1, field2) VALUES ('a','apple')
INSERT INTO @items (field1, field2) VALUES ('b','bag')
INSERT INTO @items (field1, field2) VALUES ('c','cat')

declare our input variable

declare @input_field1 varchar(max) = 'd'
declare @input_field2 varchar(max) = 'dog'

Check the record if exists. If the record exists, raise an error

if exists (	select * 
		from
			@items 
		where
			field1 = @input_field1 
		)
	begin
		raiserror ('record already exists', 11, 1)
	end

let's insert the new record

insert into @items values (@input_field1, @input_field2)
select * from @items

-