Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Table constraints problem

Table constraints problem

Scheduled Pinned Locked Moved Database
game-devcollaborationhelpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JenovaProject
    wrote on last edited by
    #1

    Hi everyone, I am creating a table to represent sporting results and so far have the following columns: --------------------------------------------------------------- game_ID date home_ID away_ID home_score away_score --------------------------------------------------------------- I have added an integrity check to ensure that home != away, as well as a 'unique' statement with (date, home) and (date, away), however this will still allow the same team to play two games on the same date; one home and one away. Is there a way to build a table so that no team can play two games on the same date or do I need to check this myself whenever I insert a new result?

    W 1 Reply Last reply
    0
    • J JenovaProject

      Hi everyone, I am creating a table to represent sporting results and so far have the following columns: --------------------------------------------------------------- game_ID date home_ID away_ID home_score away_score --------------------------------------------------------------- I have added an integrity check to ensure that home != away, as well as a 'unique' statement with (date, home) and (date, away), however this will still allow the same team to play two games on the same date; one home and one away. Is there a way to build a table so that no team can play two games on the same date or do I need to check this myself whenever I insert a new result?

      W Offline
      W Offline
      Wendelius
      wrote on last edited by
      #2

      JenovaProject wrote:

      Is there a way to build a table so that no team can play two games on the same date

      Add either unique constraint or unique index on those columns (single constraint with two fields). Just make sure that the time portion in the date is the same. Something like:

      ALTER TABLE XYZ ADD CONSTRAINT UK_SingleGame UNIQUE (date, home_id);

      Then if you want you can create a similar constraint for date and away_id.

      The need to optimize rises from a bad design. My articles[^]

      modified on Saturday, November 8, 2008 2:58 AM

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups