How to check indices with other columns?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Adithya Adi
    New Member
    • Oct 2011
    • 12

    #1

    How to check indices with other columns?

    I have 2 tables.

    Project and task

    Project_Table:
    prjct_id int, PK(identity Index)
    prjct_name nvarchar(50),(u nique index)
    prjct_position int,(unique Index)

    Task_table:
    tsk_id int, PK
    prjct_id int, (From Project_table)
    tsk_name nvarchar(50),(u nique Index)
    tsk_position int

    Say for eg., there are 5 projects, and each project consists of 10 - 12 tasks. Each Project have their positions(butto ns) in a form(VB.NET). while clicking on a particular Project Buttons, This should go to respective tasks. (This is my Idea)

    prjct_id in the task_table is not an unique index, because there is a necessity to enter 2 or more tasks in the table with the same project.

    how can i create an unique index with the tsk_position which allows only index features within one project?

    eg. project_table:
    ----prjct_id----prjct_name----prjct_position

    -------1----------a1a1-----------101
    -------2----------b2b2-----------121


    task_table:
    ----tsk_id-----project_id------tsk_name-----tsk_position

    ------1-----------1--------------aaa------------1
    ------2-----------1--------------bbb------------2
    ------3-----------2--------------xxx------------1
    ------4-----------2--------------yyy------------2
    ------5-----------1--------------ccc------------3
    ------6 ----------1--------------ddd------------4

    project_id in the task_table relates with the project_table.
    There are 4 tasks for project - a1a1 with task_id - 1,2,5,6 and task_position - 1,2,3,4 respectively

    There are 2 tasks for project - b2b2 with task_id - 4,5 and task_position - 1,2 respectively.

    task_table:
    ----tsk_id-----project_id------tsk_name-----tsk_position

    ------7-----------2--------------zzz------------2
    ------8-----------1--------------eee------------3
    (this should be wrong)
    Because there is already a task in task_position - 2 for project (b2b2) which holds the project_id 2.

    and the same case for the project 1 (a1a1) there is already a task in the position 3.

    So could anyone help me out with this avoiding such type of duplications in SQL?
    Last edited by Adithya Adi; Jan 3 '12, 07:08 AM. Reason: demo tables are not clear when submitted
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    You can create multiple UNIQUE non-clustered index to a single table.

    Happy Coding!!!


    ~~ CK

    Comment

    Working...