Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 878063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:42:47+00:00 2026-05-15T11:42:47+00:00

I’m pretty new to databases and sql. I have a problem where I have

  • 0

I’m pretty new to databases and sql. I have a problem where I have two tables which both contain a foreign key to the primary key of the other. My problem is I have a large number of elements which can have multiple names in different languages, but MUST have a single primary name/language.
alt text http://img688.imageshack.us/img688/1121/11768540.png

Firstly, I want to know if this is possible, or should I just give up already? The obvious solution is to have an extra boolean field in the ElementName table to say IsDefaultName, but it adds some extra complexity for querying and updating. If this is the best solution, how do I constrain the ElementName table to not accept any submission if IsDefaultName is set and the table already has an entry with the same ElementId and IsDefaultName set (or would I need to query this manually)?

I’m attempting to use LINQ to SQL here. The code I’m using to attempt to insert new items throws an exception at SubmitChanges with The INSERT statement conflicted with the FOREIGN KEY constraint "FK_ElementName_Element". I can understand why this is, but wondering if there’s a fix/better solution.

var db = new MyDBDataContext();
var element = new Element();
var elementName = new ElementName() {
    ElementName1 = "MyElement",
    Language = "English",
};
element.ElementName = elementName;

db.Elements.InsertOnSubmit(element);
db.ElementNames.InsertOnSubmit(elementName);
db.SubmitChanges();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T11:42:47+00:00Added an answer on May 15, 2026 at 11:42 am

    Solution 1

    element
    ------------------
    element_id
    ~....
    
    element_name
    ------------------
    element_name_id
    fk_element_id
    name
    language_id
    is_default_name  Default ( 0 )
    
    Trigger:
    if ( ( select count ( 1 ) from element_name where is_default_name = 1 ) > 1 )
    BEGIN
        raisError ( 'only 1 element_name may be marked is_default_name = true.', 16, 1 );
    END
    

    Solution 2

    element
    ------------------
    element_id ( pk )
    ~....
    
    element_name
    ------------------
    element_name_id ( pk )
    fk_element_id
    name
    language_id
    
    element_name_default
    ------------------
    fk_element_id
    fk_element_name_id
    ( pk - fk_element_id, fk_element_name_id )
    

    Solution 3

    element
    ------------------
    element_id
    fk_element_name_id_default NULL
    ~....
    
    element_name
    ------------------
    element_name_id
    fk_element_id
    name
    language_id
    
    order of code:
    * Insert to element_name
    * update of element
    

    I would stick with what you had, cause it is just fine, just:

    db.Elements.InsertOnSubmit(element);
    db.ElementNames.InsertOnSubmit(elementName);
    //I don't know this syntax to say
    //  set the property of element.fk_element_name_id_default 
    //  to the newly inserted elementName from above
    db.Elements.?.?
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a text area in my form which accepts all possible characters from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.