<i id='nuQkg'><tr id='nuQkg'><dt id='nuQkg'><q id='nuQkg'><span id='nuQkg'><b id='nuQkg'><form id='nuQkg'><ins id='nuQkg'></ins><ul id='nuQkg'></ul><sub id='nuQkg'></sub></form><legend id='nuQkg'></legend><bdo id='nuQkg'><pre id='nuQkg'><center id='nuQkg'></center></pre></bdo></b><th id='nuQkg'></th></span></q></dt></tr></i><div id='nuQkg'><tfoot id='nuQkg'></tfoot><dl id='nuQkg'><fieldset id='nuQkg'></fieldset></dl></div>
  • <legend id='nuQkg'><style id='nuQkg'><dir id='nuQkg'><q id='nuQkg'></q></dir></style></legend>

    <small id='nuQkg'></small><noframes id='nuQkg'>

      <tfoot id='nuQkg'></tfoot>

        <bdo id='nuQkg'></bdo><ul id='nuQkg'></ul>
      1. VARCHAR 作为数据库中的外键/主键好还是坏?

        VARCHAR as foreign key/primary key in database good or bad?(VARCHAR 作为数据库中的外键/主键好还是坏?)

          <tfoot id='18BuQ'></tfoot>
        1. <small id='18BuQ'></small><noframes id='18BuQ'>

            <bdo id='18BuQ'></bdo><ul id='18BuQ'></ul>
                <tbody id='18BuQ'></tbody>
              <i id='18BuQ'><tr id='18BuQ'><dt id='18BuQ'><q id='18BuQ'><span id='18BuQ'><b id='18BuQ'><form id='18BuQ'><ins id='18BuQ'></ins><ul id='18BuQ'></ul><sub id='18BuQ'></sub></form><legend id='18BuQ'></legend><bdo id='18BuQ'><pre id='18BuQ'><center id='18BuQ'></center></pre></bdo></b><th id='18BuQ'></th></span></q></dt></tr></i><div id='18BuQ'><tfoot id='18BuQ'></tfoot><dl id='18BuQ'><fieldset id='18BuQ'></fieldset></dl></div>

                • <legend id='18BuQ'><style id='18BuQ'><dir id='18BuQ'><q id='18BuQ'></q></dir></style></legend>

                  本文介绍了VARCHAR 作为数据库中的外键/主键好还是坏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如果我使用 ID nr:s 而不是 VARCHARS 作为外键会更好吗?使用 ID nr:s isstead of VARCHARS 作为主键是否更好?通过 ID nr 我的意思是 INT!

                  Is it better if I use ID nr:s instead of VARCHARS as foreign keys? And is it better to use ID nr:s isntead of VARCHARS as Primary Keys? By ID nr I mean INT!

                  这就是我现在所拥有的:

                  category table:
                  cat_id ( INT ) (PK)
                  cat_name (VARCHAR)
                  
                  category options table:
                  option_id ( INT ) (PK)
                  car_id ( INT ) (FK)
                  option_name ( VARCHAR ) 
                  

                  我可以这么认为:

                  category table:
                  cat_name (VARCHAR) (PK)
                  
                  category options table:
                  cat_name ( VARCHAR ) (FK)
                  option_name ( VARCHAR ) ( PK )
                  

                  还是我的想法完全错了?

                  Or am I thinking completely wrong here?

                  推荐答案

                  VARCHAR 用于任何 KEY 的问题是它们可以容纳 WHITE SPACE.空白由任何非屏幕可读字符组成,例如空格制表符、回车符等.当您开始追查为什么表不返回带有额外空格的记录时,使用 VARCHAR 作为键会使您的生活变得困难他们的钥匙.

                  The problem with VARCHAR being used for any KEY is that they can hold WHITE SPACE. White space consists of ANY non-screen-readable character, like spaces tabs, carriage returns etc. Using a VARCHAR as a key can make your life difficult when you start to hunt down why tables aren't returning records with extra spaces at the end of their keys.

                  当然,您可以使用 VARCHAR,但是您必须非常小心输入和输出.它们还会占用更多空间,并且在执行查询时可能会更慢.

                  Sure, you CAN use VARCHAR, but you do have to be very careful with the input and output. They also take up more space and are likely slower when doing a Queries.

                  整数类型有一个包含 10 个有效字符的小列表,0,1,2,3,4,5,6,7,8,9.它们是用作密钥的更好的解决方案.

                  Integer types have a small list of 10 characters that are valid, 0,1,2,3,4,5,6,7,8,9. They are a much better solution to use as keys.

                  如果您想获得更快查找的优势,您可以始终使用基于整数的键并使用 VARCHAR 作为 UNIQUE 值.

                  You could always use an integer-based key and use VARCHAR as a UNIQUE value if you wanted to have the advantages of faster lookups.

                  这篇关于VARCHAR 作为数据库中的外键/主键好还是坏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
                  SQL query to group by day(按天分组的 SQL 查询)
                  What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
                  MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
                  MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
                  Include missing months in Group By query(在 Group By 查询中包含缺失的月份)

                    <bdo id='aQ15l'></bdo><ul id='aQ15l'></ul>
                      • <i id='aQ15l'><tr id='aQ15l'><dt id='aQ15l'><q id='aQ15l'><span id='aQ15l'><b id='aQ15l'><form id='aQ15l'><ins id='aQ15l'></ins><ul id='aQ15l'></ul><sub id='aQ15l'></sub></form><legend id='aQ15l'></legend><bdo id='aQ15l'><pre id='aQ15l'><center id='aQ15l'></center></pre></bdo></b><th id='aQ15l'></th></span></q></dt></tr></i><div id='aQ15l'><tfoot id='aQ15l'></tfoot><dl id='aQ15l'><fieldset id='aQ15l'></fieldset></dl></div>
                      • <legend id='aQ15l'><style id='aQ15l'><dir id='aQ15l'><q id='aQ15l'></q></dir></style></legend>
                          <tbody id='aQ15l'></tbody>
                      • <small id='aQ15l'></small><noframes id='aQ15l'>

                          <tfoot id='aQ15l'></tfoot>