Results 1 to 2 of 2

Thread: Views and RI

  1. #1
    Join Date
    Mar 2003
    Location
    Australia
    Posts
    59

    Views and RI

    This may seem like a strange question but....

    I was modelling a game of chess and came up with this representation for the chess board..

    GameBoard
    X TINYINT NOT NULL CHECK(X BETWEEN 1 AND 8)
    Y TINYINT NOT NULL CHECK(Y BETWEEN 1 AND 8)
    KEY(X,Y)

    I then created a view that returns a single column displaying the chess notation for these corordinate eg. a1,a2..h8

    I obviously have another table (Moves) which has the current Piece and what square it currently is on and I would have liked to enforce the "square" value via RI between the GameBoard and Move.

    I quickly realised that I had made that classic logical/physical mistake in regards to this. ie: In the logical model Square is a type with 2 representations, X,Y and Notation. In the end I simply added a rather lengthy CHECK constraint on the square column in the Moves table...

    But it did raise may interest..

    Is there anything in the relational model that prohibits using a view in a RI constraint?

  2. #2
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171

    Re: Views and RI

    Don't have my C J Date books to hand, but I don't think there is. The foreign key "references" constraint is really just a convenient shorthand for a database constraint like "FORALL child EXISTS (parent WHERE parent.pk = child.parent_fk)". I don't recall any prohibition on using views in database constraints in general, and can't see any reason for there being any.

Posting Permissions

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