Results 1 to 7 of 7
  1. #1
    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

  2. #2
    Join Date
    Nov 2003
    Posts
    2,933
    Which DBMS are you using? This kind of unique index highly depends on the used DBMS

  3. #3
    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

  4. #4
    Join Date
    Nov 2003
    Posts
    2,933
    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?

  5. #5
    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.

  6. #6
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    1. yes
    2. deny INSERT after the first row, allow only UPDATE
    3. yes
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  7. #7
    Join Date
    Mar 2011
    Posts
    4
    Thanks to you two, really appreciated!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •