Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

FK relationship in MySQL in WorkBench IDE

Posted on 2010-08-12
4
653 Views
Last Modified: 2013-11-08
i'm having trouble creating a one to many foreign key relationship between two InnoDB tables that I have created in my MySQL db using the workbench IDE. I'm using this in conjuction with vs 2010 and the entity framework. so i'm looking for some visual aids (tutorials preferably) that address this and show me the proper way to achieve this. Any suggestions and or suggested resources would be appreciated.
0
Comment
Question by:mikesExpertExchange
  • 2
  • 2
4 Comments
 
LVL 42

Accepted Solution

by:
dqmq earned 500 total points
ID: 33424308
You implement a one-many relationship simply by including a key of the parent table (the one) in the child table (the many).  Usually, it is the primary key, but any unique key will do.

If you want the database to enforce the integrity of that relationship, then you use a foreign key constraint.  The foreign key constraint is a "rule" applied to the child table that guarantees the value of the foreign key will be present in the referenced unique key of the parent table.

alter table CHILDTABLE add constraint CONSTRAINTNAME foreign key (COL1, COL2...) references PARENTTABLE (COL1, COL2)

I haven't used MySQL IDE, but most development enviornments provide a graphical way to create the necessary keys and constraints.  Someone else will need to assist you with that.  
0
 
LVL 1

Author Comment

by:mikesExpertExchange
ID: 33425010
thank you. as a sidenote, good, bad or indifferent, can you have a primary key that is a character string?
0
 
LVL 42

Expert Comment

by:dqmq
ID: 33432608
Absolutely!  But if it's longer than 16 bytes, I'd reconsider (for optimization reasons).
0
 
LVL 1

Author Comment

by:mikesExpertExchange
ID: 33432781
thanks for your help....
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
jquery tab header text 1 23
VS 2017 18 50
Giant ibd file for our biggest table on mysql 2 18
looking for an ASP.net report designer 4 11
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question