User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Database Design section within the Web Development category of DaniWeb, a massive community of 426,314 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,323 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Database Design advertiser: Programming Forums

Uniqueness Dependent on another Column?

Join Date: Feb 2008
Posts: 5
Reputation: im.thatoneguy is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
im.thatoneguy im.thatoneguy is offline Offline
Newbie Poster

Uniqueness Dependent on another Column?

  #1  
Feb 8th, 2008
I have a database with let's say two tables as follows:

Products Table

ProductID | ProductName

and

Widgets Table
WidgetID | ProductID (Foreign Key) | Position


Now how do I set it up if I want a variable number of widgets that attach to a product. But I want to ensure uniqueness in the Position Column WHERE ProductID is XYZ.


So I want to be able to have the following entries in Widgets:

0 | 1 | 1
1 | 1 | 2
2 | 2 | 1
3 | 1 | 3

But not:

0 | 1 | 1
1 | 1 | 2
2 | 1 | 1
3 | 1 | 3

I'm using MySQL but I'm open to other databases. Or do I just need to handle this on the application side to check for a previous entry. I don't mind doing this either, but if there is a way to ensure that no duplicates get entered at all costs would be idea.

Thanks!
Gavin
Last edited by im.thatoneguy : Feb 8th, 2008 at 7:15 pm.
AddThis Social Bookmark Button
Reply With Quote  
All times are GMT -4. The time now is 10:36 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC