How to create relationship

  • When I try to create a relationship between modeloptionID in the modeloptions  table and "name" in the model table I get the error THE ALTER TABLE statement conficted with the FOREIGN KEY constraint "FK_Model_modeloptions". The conflict occurred in table dbo.modeloptions column "modeloptionID". How can I create FK_modeloptions_Model without any errors. Also is this the correct way to allow primary key data to repeat as demonstrated in my screenshot?

  • Can you post your table definitions as text instead of screen shots? See the first link in my signature for best practices when posting questions.

    The error message you received means there is data in the table that violates the foreign key you are trying to create.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • OK, I can't make any sense of the pictures you've attached.  Are you trying to create a foreign key from model to modeloption?  If so, and if modeloptionID is the primary key of the modeloption table, that is the column you would want to have in your model table to create the foreign key on.  If you try to match a name to an ID that won't work, and defeats the purpose of normalizing your data as you would have to maintain the name in multiple places.  The relations between family, series, and model tables look confusing as well.  It might be clearer to us what you are trying to do if you posted DDL statements like Sean asked for.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply