I have a database that needs to have unique values wherein it will provide an error saying "Username already exist" and will not add to database. How to do this?
AngelicOne 4 Posting Whiz
Recommended Answers
Jump to PostYou can select the user name from the database to see if it is already used:
SELECT COUNT(*) FROM user_table WHERE userid = 'WhateverTheUserTypedIn'
If this returns anything other than zero, that userid is already in use.In some databases you could make the userid field an identity field, …
Jump to PostAlternatively, you can use IF ELSE in queries with SQL Server 2000 or newer.
You can check if the item exists, if it doesn't then insert it. I have done something like this in the past:IF EXISTS ( SELECT * FROM user_table WHERE userid = @userID )
BEGIN
…
Jump to PostFor return values use return...
ie:
if @count=0
insert into Author values (@authorname)
return 1
else
return 0if 1 is returned then it succeeded, if 0 is returned then it failed.
At that point you simply check the returned value as it is received from the …
All 9 Replies
Momerath 1,327 Nearly a Senior Poster Featured Poster
AngelicOne commented: thanks +1
Geekitygeek 480 Nearly a Posting Virtuoso
PierlucSS commented: good one. +1
AngelicOne 4 Posting Whiz
Momerath 1,327 Nearly a Senior Poster Featured Poster
AngelicOne 4 Posting Whiz
Momerath 1,327 Nearly a Senior Poster Featured Poster
AngelicOne 4 Posting Whiz
Lusiphur 185 Practically a Posting Shark Team Colleague Featured Poster
AngelicOne 4 Posting Whiz
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.