relations.html 9.9 KB

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