If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > Only one active row

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-01-11, 15:41
Biene_Maja Biene_Maja is offline
Registered User
 
Join Date: Mar 2011
Posts: 4
Question Only one active row

Hi,

i have a table "projects". And only one project can be active at one time. How do i design this? I had in mind to make a table "active_project" and save the name of the active project in there. So my questions are:
1. Would that be an appropriate way to do it?
2. Is there a way in mysql to limit the number of rows in this table to 1?
3. And am i right that the relation between the two tables is 1:1 then?

Thanks for help

Biene_Maja
Reply With Quote
  #2 (permalink)  
Old 03-01-11, 15:59
shammat shammat is offline
Registered User
 
Join Date: Nov 2003
Posts: 2,407
Which DBMS are you using? This kind of unique index highly depends on the used DBMS
Reply With Quote
  #3 (permalink)  
Old 03-01-11, 16:13
Biene_Maja Biene_Maja is offline
Registered User
 
Join Date: Mar 2011
Posts: 4
Quote:
Originally Posted by shammat View Post
Which DBMS are you using? This kind of unique index highly depends on the used DBMS
I use MySQL
Reply With Quote
  #4 (permalink)  
Old 03-01-11, 16:16
shammat shammat is offline
Registered User
 
Join Date: Nov 2003
Posts: 2,407
Quote:
Originally Posted by Biene_Maja View Post
I use MySQL
Then I don't have a solution (as it does not support partial indexes).

Maybe a moderator can move this to the MySQL forum?
Reply With Quote
  #5 (permalink)  
Old 03-01-11, 16:27
Biene_Maja Biene_Maja is offline
Registered User
 
Join Date: Mar 2011
Posts: 4
I mean it's firstly a design question. Even if i don't could set the max row to 1, i could make it so and then just update the first row everytime and never add one. It would just be another "safety" layer if i could set the max row to 1. I'm more interested if it is the "right" solution, from a design standpoint, at all.
Reply With Quote
  #6 (permalink)  
Old 03-01-11, 16:38
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
1. yes
2. deny INSERT after the first row, allow only UPDATE
3. yes
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #7 (permalink)  
Old 03-01-11, 16:50
Biene_Maja Biene_Maja is offline
Registered User
 
Join Date: Mar 2011
Posts: 4
Thanks to you two, really appreciated!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Trackbacks are On
Pingbacks are On
Refbacks are On