Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Question

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-03-05 : 09:02:22
ravi writes "hello when i send some vales to sql database ,
i need sample sql query for indentifyng duplicate records
i mean i crate one table in sql in that fields name , age
and i put name field as primary key,
ok in my asp code i try worite code for inserting the vales from browser now i had problem with when i send duplicate record its giving error , i want answer when i send the duplicate record i want answer as "user already exits",
bye
ravi"

Nazim
A custom title

1408 Posts

Posted - 2002-03-05 : 09:15:33
Before actually giving a request to insert you need to check for the existence of that particular value in your table.


create procedure Insert_unique( @mname varchar(40), @mage int)
as
declare @Cnt int

select @Cnt=isnull(count(*),0) from tablename where name=@mname

if @Cnt>0
RaiseError(5001,16,'Record Already exists with this name')


insert into tablename(name,age) values(@mname,@mage)
Go

HTH



--------------------------------------------------------------
Go to Top of Page

dsdeming

479 Posts

Posted - 2002-03-05 : 09:16:29
The simplest solution would be to trap the specific error number for primary key violation in the calling code. Once you've trapped it, you can send email notifications, pop up a message box, etc.

Go to Top of Page
   

- Advertisement -