Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET Database and Reporting > unique username in user table


Reply
 
Thread Tools Display Modes
  #1  
Old 08-25-2008, 01:50 AM
peanutong peanutong is offline
Newcomer
 
Join Date: Aug 2008
Posts: 2
Default unique username in user table


how do i create restrictions whereby there cannot be two similar username in the table, while registering?

i am using SQL server.

thank you.
Reply With Quote
  #2  
Old 08-25-2008, 07:15 AM
gpraceman's Avatar
gpraceman gpraceman is offline
Contributor

* Expert *
 
Join Date: Sep 2002
Location: Highlands Ranch, CO
Posts: 556
Default

Just run a query to verify that the new user name doesn't already exist in the table first, then do the insert.
__________________
Awana Grand Prix and Pinewood Derby racing - Where a child, an adult and a small block of wood combine for a lot of fun and memories.
Reply With Quote
  #3  
Old 08-25-2008, 07:35 AM
wayneph's Avatar
wayneph wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

It's better to add a Constraint on the table so that SQL doesn't allow the second occurance in. A Primary or Unique Constraint on the Username column should do the trick in this case.

What happens when there are multiple developers on a project and not everyone codes the same checks in? I'm not saying that the application shouldn't check to see if it's there, but the responsibility for clean data should be held in the database design.
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
  #4  
Old 08-25-2008, 07:42 AM
gpraceman's Avatar
gpraceman gpraceman is offline
Contributor

* Expert *
 
Join Date: Sep 2002
Location: Highlands Ranch, CO
Posts: 556
Default

Quote:
Originally Posted by wayneph View Post
What happens when there are multiple developers on a project and not everyone codes the same checks in? I'm not saying that the application shouldn't check to see if it's there, but the responsibility for clean data should be held in the database design.
So true.
__________________
Awana Grand Prix and Pinewood Derby racing - Where a child, an adult and a small block of wood combine for a lot of fun and memories.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->