relations.html 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>Relations &#8212; phpMyAdmin 4.9.10 documentation</title>
  7. <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
  8. <link rel="stylesheet" href="_static/classic.css" type="text/css" />
  9. <script id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
  10. <script src="_static/jquery.js"></script>
  11. <script src="_static/underscore.js"></script>
  12. <script src="_static/doctools.js"></script>
  13. <link rel="index" title="Index" href="genindex.html" />
  14. <link rel="search" title="Search" href="search.html" />
  15. <link rel="copyright" title="Copyright" href="copyright.html" />
  16. <link rel="next" title="Charts" href="charts.html" />
  17. <link rel="prev" title="User management" href="privileges.html" />
  18. </head><body>
  19. <div class="related" role="navigation" aria-label="related navigation">
  20. <h3>Navigation</h3>
  21. <ul>
  22. <li class="right" style="margin-right: 10px">
  23. <a href="genindex.html" title="General Index"
  24. accesskey="I">index</a></li>
  25. <li class="right" >
  26. <a href="charts.html" title="Charts"
  27. accesskey="N">next</a> |</li>
  28. <li class="right" >
  29. <a href="privileges.html" title="User management"
  30. accesskey="P">previous</a> |</li>
  31. <li class="nav-item nav-item-0"><a href="index.html">phpMyAdmin 4.9.10 documentation</a> &#187;</li>
  32. <li class="nav-item nav-item-1"><a href="user.html" accesskey="U">User Guide</a> &#187;</li>
  33. <li class="nav-item nav-item-this"><a href="">Relations</a></li>
  34. </ul>
  35. </div>
  36. <div class="document">
  37. <div class="documentwrapper">
  38. <div class="bodywrapper">
  39. <div class="body" role="main">
  40. <div class="section" id="relations">
  41. <span id="id1"></span><h1>Relations<a class="headerlink" href="#relations" title="Permalink to this headline">¶</a></h1>
  42. <p>phpMyAdmin allows relationships (similar to foreign keys) using MySQL-native
  43. (InnoDB) methods when available and falling back on special phpMyAdmin-only
  44. features when needed. There are two ways of editing these relations, with the
  45. <em>relation view</em> and the drag-and-drop <em>designer</em> – both of which are explained
  46. on this page.</p>
  47. <div class="admonition note">
  48. <p class="admonition-title">Note</p>
  49. <p>You need to have configured the <a class="reference internal" href="setup.html#linked-tables"><span class="std std-ref">phpMyAdmin configuration storage</span></a> for using phpMyAdmin
  50. only relations.</p>
  51. </div>
  52. <div class="section" id="technical-info">
  53. <h2>Technical info<a class="headerlink" href="#technical-info" title="Permalink to this headline">¶</a></h2>
  54. <p>Currently the only MySQL table type that natively supports relationships is
  55. InnoDB. When using an InnoDB table, phpMyAdmin will create real InnoDB
  56. relations which will be enforced by MySQL no matter which application accesses
  57. the database. In the case of any other table type, phpMyAdmin enforces the
  58. relations internally and those relations are not applied to any other
  59. application.</p>
  60. </div>
  61. <div class="section" id="relation-view">
  62. <h2>Relation view<a class="headerlink" href="#relation-view" title="Permalink to this headline">¶</a></h2>
  63. <p>In order to get it working, you first have to properly create the
  64. [[pmadb|pmadb]]. Once that is setup, select a table’s “Structure” page. Below
  65. the table definition, a link called “Relation view” is shown. If you click that
  66. link, a page will be shown that offers you to create a link to another table
  67. for any (most) fields. Only PRIMARY KEYS are shown there, so if the field you
  68. are referring to is not shown, you most likely are doing something wrong. The
  69. drop-down at the bottom is the field which will be used as the name for a
  70. record.</p>
  71. <div class="section" id="relation-view-example">
  72. <h3>Relation view example<a class="headerlink" href="#relation-view-example" title="Permalink to this headline">¶</a></h3>
  73. <img alt="_images/pma-relations-relation-view-link.png" src="_images/pma-relations-relation-view-link.png" />
  74. <img alt="_images/pma-relations-relation-link.png" src="_images/pma-relations-relation-link.png" />
  75. <p>Let’s say you have categories and links and one category can contain several links. Your table structure would be something like this:</p>
  76. <ul class="simple">
  77. <li><p><cite>category.category_id</cite> (must be unique)</p></li>
  78. <li><p><cite>category.name</cite></p></li>
  79. <li><p><cite>link.link_id</cite></p></li>
  80. <li><p><cite>link.category_id</cite></p></li>
  81. <li><p><cite>link.uri</cite>.</p></li>
  82. </ul>
  83. <p>Open the relation view (below the table structure) page for the <cite>link</cite> table and for <cite>category_id</cite> field, you select <cite>category.category_id</cite> as master record.</p>
  84. <p>If you now browse the link table, the <cite>category_id</cite> field will be a clickable hyperlink to the proper category record. But all you see is just the <cite>category_id</cite>, not the name of the category.</p>
  85. <img alt="_images/pma-relations-relation-name.png" src="_images/pma-relations-relation-name.png" />
  86. <p>To fix this, open the relation view of the <cite>category</cite> table and in the drop down at the bottom, select “name”. If you now browse the link table again and hover the mouse over the <cite>category_id</cite> hyperlink, the value from the related category will be shown as tooltip.</p>
  87. <img alt="_images/pma-relations-links.png" src="_images/pma-relations-links.png" />
  88. </div>
  89. </div>
  90. <div class="section" id="designer">
  91. <h2>Designer<a class="headerlink" href="#designer" title="Permalink to this headline">¶</a></h2>
  92. <p>The Designer feature is a graphical way of creating, editing, and displaying
  93. phpMyAdmin relations. These relations are compatible with those created in
  94. phpMyAdmin’s relation view.</p>
  95. <p>To use this feature, you need a properly configured <a class="reference internal" href="setup.html#linked-tables"><span class="std std-ref">phpMyAdmin configuration storage</span></a> and
  96. must have the <span class="target" id="index-0"></span><a class="reference internal" href="config.html#cfg_Servers_table_coords"><code class="xref config config-option docutils literal notranslate"><span class="pre">$cfg['Servers'][$i]['table_coords']</span></code></a> configured.</p>
  97. <p>To use the designer, select a database’s structure page, then look for the
  98. <span class="guilabel">Designer</span> tab.</p>
  99. <p>To export the view into PDF, you have to create PDF pages first. The Designer
  100. creates the layout, how the tables shall be displayed. To finally export the
  101. view, you have to create this with a PDF page and select your layout, which you
  102. have created with the designer.</p>
  103. <div class="admonition seealso">
  104. <p class="admonition-title">See also</p>
  105. <p><a class="reference internal" href="faq.html#faqpdf"><span class="std std-ref">6.8 How can I produce a PDF schema of my database?</span></a></p>
  106. </div>
  107. </div>
  108. </div>
  109. <div class="clearer"></div>
  110. </div>
  111. </div>
  112. </div>
  113. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  114. <div class="sphinxsidebarwrapper">
  115. <h3><a href="index.html">Table of Contents</a></h3>
  116. <ul>
  117. <li><a class="reference internal" href="#">Relations</a><ul>
  118. <li><a class="reference internal" href="#technical-info">Technical info</a></li>
  119. <li><a class="reference internal" href="#relation-view">Relation view</a><ul>
  120. <li><a class="reference internal" href="#relation-view-example">Relation view example</a></li>
  121. </ul>
  122. </li>
  123. <li><a class="reference internal" href="#designer">Designer</a></li>
  124. </ul>
  125. </li>
  126. </ul>
  127. <h4>Previous topic</h4>
  128. <p class="topless"><a href="privileges.html"
  129. title="previous chapter">User management</a></p>
  130. <h4>Next topic</h4>
  131. <p class="topless"><a href="charts.html"
  132. title="next chapter">Charts</a></p>
  133. <div role="note" aria-label="source link">
  134. <h3>This Page</h3>
  135. <ul class="this-page-menu">
  136. <li><a href="_sources/relations.rst.txt"
  137. rel="nofollow">Show Source</a></li>
  138. </ul>
  139. </div>
  140. <div id="searchbox" style="display: none" role="search">
  141. <h3 id="searchlabel">Quick search</h3>
  142. <div class="searchformwrapper">
  143. <form class="search" action="search.html" method="get">
  144. <input type="text" name="q" aria-labelledby="searchlabel" />
  145. <input type="submit" value="Go" />
  146. </form>
  147. </div>
  148. </div>
  149. <script>$('#searchbox').show(0);</script>
  150. </div>
  151. </div>
  152. <div class="clearer"></div>
  153. </div>
  154. <div class="related" role="navigation" aria-label="related navigation">
  155. <h3>Navigation</h3>
  156. <ul>
  157. <li class="right" style="margin-right: 10px">
  158. <a href="genindex.html" title="General Index"
  159. >index</a></li>
  160. <li class="right" >
  161. <a href="charts.html" title="Charts"
  162. >next</a> |</li>
  163. <li class="right" >
  164. <a href="privileges.html" title="User management"
  165. >previous</a> |</li>
  166. <li class="nav-item nav-item-0"><a href="index.html">phpMyAdmin 4.9.10 documentation</a> &#187;</li>
  167. <li class="nav-item nav-item-1"><a href="user.html" >User Guide</a> &#187;</li>
  168. <li class="nav-item nav-item-this"><a href="">Relations</a></li>
  169. </ul>
  170. </div>
  171. <div class="footer" role="contentinfo">
  172. &#169; <a href="copyright.html">Copyright</a> 2012 - 2018, The phpMyAdmin devel team.
  173. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.4.3.
  174. </div>
  175. </body>
  176. </html>