Insert Unique Value in MS SQL Database By Using SQL Stored Procedure

When we enter some data in database then its repetition is major problem for at all. Here I am using a table with Mobile No. as primary key and trying to insert unique value to it.

You can see database in this image.
 
Stored procedure wants phone no as a parameter which can be passed easily

create procedure insert_unique
(
@phone numeric(10,0)
)
as
begin
INSERT INTO
PhoneData(Phoneno)
    SELECT @phone
WHERE NOT EXISTS (SELECT phoneno FROM PhoneData WHERE Phoneno = @phone)
end

Pass your phone no in this procedure and it will insert only unique record.

Comments

Popular posts from this blog

DTS package conversion in SSIS to use in SQL 2012 and SQL 2016

Infinite Scroll in Asp.Net C# using Javascript without Third party Plugin

Add Custom Tags in Web config file in ASP .Net