www.webdeveloper.com
Results 1 to 4 of 4

Thread: Unique constraint

  1. #1
    Join Date
    Jan 2013
    Posts
    20

    Unique constraint

    Hello,

    I am slightly confused about one task regarding usage of unique constraint. I've got two tables:

    TABLE ROOM
    TABLE BUILDING

    The requirement is that table ROOM has room code which must be unique only within a particular building (i've got 4 buildings). Not really sure how to do that. Any ideas?

    Thanks is advance.

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,221
    You can have a unique index across multiple columns, so presumably your "room" table would have a unique index on the combination of room number and building id.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Jan 2013
    Posts
    20
    NogDog,

    Thanks for the reply. Maybe you could give me some example how to do that?
    I've got 4 buildings:
    1
    2
    3
    4

    Each building has 4 rooms:
    A
    B
    C
    D

    Room code is unique only within a particular building:
    1A, 1B, 1C, 1D.
    2A, 2B, 2C, 2D.
    3A, 3B, 3C, 3D.
    4A, 4B, 4C, 4D.

    How can I make a constraint from this?

  4. #4
    Join Date
    Sep 2011
    Posts
    59
    so, add table BuildingRooms with biuldingId, RoomId and it is unique compbination

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles