Home Forums SQL Server 2008 SQL Server Newbies Limiting list of values for a column from another table's column RE: Limiting list of values for a column from another table's column

  • So just to make sure that I understand your question. Before inserting a record into Table1 you want to verify that Table1.Col2 exists in Col3 from Table2 and that Col1 is set to a certain value. Is this correct so far?

    Can you create a stored procedure to handle the inserts and do the necessary checks before inserting the values?

    If not:

    First question is the value in Table2.Col1 also in Table1? Is it static or is it derived by a value in Table1?

    Second question is the combination of Col3 and Col1 in Table2 unique and can you create a unique index on the values? If so, you maybe able to create a foreign key on the unique index (depending on the answer to question 1)

    An instead of trigger would work in this case, but you will have the administration overhead and performance hit from using the trigger so test it and make sure that it is acceptable.

    Also, if you could provide some create table statements along with some sample data that would help. See the article in my signature for details on how to do this.



    Microsoft Certified Master - SQL Server 2008
    Follow me on twitter: @keith_tate

    Forum Etiquette: How to post data/code on a forum to get the best help[/url]