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

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

                  相关文档推荐

                  Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32)(超出最大存储过程、函数、触发器或视图嵌套级别(限制 32))
                  How to View Oracle Stored Procedure using SQLPlus?(如何使用 SQLPlus 查看 Oracle 存储过程?)
                  How to debug stored procedure in VS 2015?(如何在 VS 2015 中调试存储过程?)
                  Set the variable result, from query(设置变量结果,来自查询)
                  What is dynamic SQL?(什么是动态 SQL?)
                  Mysql - How to quit/exit from stored procedure(Mysql - 如何退出/退出存储过程)

                    <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>