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

    1. <small id='UW02f'></small><noframes id='UW02f'>

      <legend id='UW02f'><style id='UW02f'><dir id='UW02f'><q id='UW02f'></q></dir></style></legend>

      1. <tfoot id='UW02f'></tfoot>

        ΪʲôҪʹÓá°·Ç¿ÕÖ÷¼ü"?ÔÚ TSQL ÖÐ?

        ʱ¼ä£º2024-04-16

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

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

                1. <tfoot id='xFcEd'></tfoot>

                  ±¾ÎĽéÉÜÁËΪʲôҪʹÓá°·Ç¿ÕÖ÷¼ü"?ÔÚ TSQL ÖÐ?µÄ´¦Àí·½·¨£¬¶Ô´ó¼Ò½â¾öÎÊÌâ¾ßÓÐÒ»¶¨µÄ²Î¿¼¼ÛÖµ£¬ÐèÒªµÄÅóÓÑÃÇÏÂÃæËæןú°æÍøµÄС±àÀ´Ò»Æðѧϰ°É£¡

                  ÎÊÌâÃèÊö

                  ÎÒÔÚ²©¿Í¡¢ÎÄÕ¡¢Êé¼®¡¢ÂÛ̳¡¢SO µÈÖÐµÄ TSQL Öд´½¨±íµÄ½Å±¾Öо­³£¿´µ½·Ç¿ÕÖ÷¼ü".

                  I am seeing too frequently "not null primary key" in scripts creating tables in TSQL in blogs, articles, books, forums, here in SO, etc.

                  ÀýÈ磬Èç¹ûËÑË÷not null"NEARprimary key"sql server"£¬BING »á¸ø³ö 630,000 ¸ö½á¹û((½öÓ¢ÎÄ):
                  http://www.bing.com/search?q=%22not+null%22+NEAR+%22primary+key%22+%22sql+server%22&go=&form=QBRE&filt=lf

                  For example, BING gives 630,000 results ((just in English) if to search against "not null" NEAR "primary key" "sql server":
                  http://www.bing.com/search?q=%22not+null%22+NEAR+%22primary+key%22+%22sql+server%22&go=&form=QBRE&filt=lf

                  ÎÒÒ»Ö±ÈÏΪNOT NULL"ÊÇ PRIMARY KEY ¶¨Òå²»¿É·Ö¸îµÄÒ»²¿·Ö£¬ÖÁÉÙÔÚ SQL Server ÖÐÊÇÕâÑù.
                  ÎÒÊÔͼÔÚ SQL Server Öд´½¨Ò»¸ö´øÓкͲ»´øÓÐNOT NULL"µÄÖ÷¼üµÄ±í£¬µ«ÎÞ·¨ÕÆÎÕ¿ÉÄܵÄÇø±ð.

                  I always perceived "NOT NULL" as inseparable part of definition of PRIMARY KEY, at least in SQL Server.
                  I tried to create a tables with Primary KEYs with and without "NOT NULL" in SQL Server but could not grasp the possible difference.

                  Ϊʲô¼´Ê¹ÔÚ¿ìËÙ(¼ò¶Ì)²åͼÖÐÒ²¶¼Ê¹ÓÃNOT NULL"À´´´½¨Ö÷¼ü?

                  Why do all use "NOT NULL" for creating a primary key even in fast (short) illustrations?

                  ¸üÐÂ:
                  NULL ÈçºÎ±êʶÈκÎÄÚÈÝ»òΨһ(ÒÔ¼°ÔÚÔÊÐíµÄÇé¿öÏ·ÀÖ¹³öÏÖ¶à¸ö NULL)?ËüÊÇδָ¶¨µÄ¡¢È±Ê§µÄ¡¢²»ÊÊÓõÄÖµ

                  Update:
                  How can NULL identify anything or be unique (as well as preventing multiple NULLs if one is permitted)? It is unspecified, missing, not applicable value

                  ÎÒµÄÎÊÌâÒ²°µÊ¾ÁË×ÓÎÊÌâ:
                  Èç¹ûΪ PK ¶¨ÒåÁËNOT NULL"£¬ÎªÊ²Ã´²»Ö¸¶¨ UNIQUE?
                  PKµÄ¶¨ÒåÊÇʲô.ÊÇ UNIQUE CONSTRAINT + NOT NULL »¹ÊÇ UNIQUE INDEX(ÄÇôΪʲô NOT NULL)?
                  Çë¸øÎÒÁ´½Óµ½ËüµÄ msdn Îĵµ.

                  My question also implied subquestions:
                  if one defines "NOT NULL" for PK, why then UNIQUE is not specified?
                  And what is the definition of PK. IS it UNIQUE CONSTRAINT + NOT NULL or UNIQUE INDEX (then why NOT NULL)?
                  Plz give me link to msdn docs on it.

                  ¸üР2:@Damien_The_Unbeliever

                  Update2: @Damien_The_Unbeliever

                  ΪʲôûÓÐNOT NULL"¾Í²»ÊÇͬÒå´Ê?

                  Why is not synonym without "NOT NULL"?

                  CREATE TABLE T3 
                  (
                      PK int -- NOT NULL commented out
                      , nonPK int -- to double-check my sanity 
                      , constraint PK_vgv8 PRIMARY KEY (PK) on [PRIMARY]
                  ) 
                  

                  ÈÔÈ»²»ÔÊÐí NULL ¸ø³ö:

                  still does not permit NULL giving:

                  <Сʱ>

                  Microsoft SQL Server ¹ÜÀí¹¤×÷ÊÒ


                  Microsoft SQL Server Management Studio

                  δ¸üÐÂÈκÎÐÐ.

                  µÚ 2 ÐÐÖеÄÊý¾ÝδÌá½».´íÎóÀ´Ô´:.Net SqlClient Êý¾ÝÌṩ³ÌÐò.´íÎóÏûÏ¢:ÎÞ·¨½«Öµ NULL ²åÈëµ½ÁÐ 'PK'¡¢±í 'TestData.dbo.T3' ÖУ»Áв»ÔÊÐí¿ÕÖµ.²åÈëʧ°Ü.

                  The data in row 2 was not committed. Error Source: .Net SqlClient Data Provider. Error Message: Cannot insert the value NULL into column 'PK', table 'TestData.dbo.T3'; column does not allow nulls. INSERT fails.

                  ÉùÃ÷ÒÑÖÕÖ¹.

                  ¸üÕý´íÎó²¢ÖØÊÔ»ò°´ ESC È¡Ïû¸ü¸Ä.

                  Correct the errors and retry or press ESC to cancel the change(s).

                  ºÃµÄ°ïÖú

                  ¸üР3:
                  Õ⣬¸ÅÄîºÍÊõÓﶨÒ壬¿ÉÄÜ¿´ÆðÀ´²»ÇÐʵ¼Ê.
                  ²¢·ÇÈç´Ë£¬¶Ô»ù±¾¸ÅÄîµÄһЩ´íÎó³ÂÊö(ÔÚ¹µÍ¨/ÌÖÂÛÆÚ¼äÆäËûÈ˵ÄÒâ¼û)×ãÒÔ±»ÊÓΪ°×³Õ£¬²¢ÔÚרҵ»¥¶¯ºÍ¹µÍ¨ÖÐÔì³ÉÕÏ°­.

                  Update3:
                  This, concepts and terms definition, might appear as impractical nuisance.
                  It is not, some wrong statement (in the opinion of other(s) during communication/discussion) on a basic notion is enough to be considered a moron and create barriers in professional interaction and communication.

                  ÎÒÍüÁË˵£¬NOT NULL ÊÇÓÉ SSMS ±àдµÄÓÃÓÚ PK µÄ½Å±¾£¡

                  I forgot to tell, NOT NULL is scripted by SSMS for PK!

                  ÍƼö´ð°¸

                  ΪÇåÎúÆð¼û½øÐÐÁ˱༭

                  ¸ù¾Ý SQL ¹æ·¶£¬Ö÷¼ü²»ÄÜ°üº¬ NULL.ÕâÒâζ×ÅÓÃNOT NULL PRIMARY KEY"»òPRIMARY KEY"×°ÊÎÒ»ÁÐÓ¦¸Ã×öͬÑùµÄÊÂÇé.µ«ÊÇÄúÒÀÀµÓÚÕýÈ·×ñÑ­ SQL ±ê×¼µÄ SQL ÒýÇæ.ÀýÈ磬ÓÉÓÚÔçÆÚ´íÎó£¬SQL Lite ûÓÐÕýȷʵÏÖ±ê×¼²¢ÔÊÐí·ÇÕûÊýÖ÷¼üÖеĿÕÖµ(Çë²ÎÔÄ sqlite.org/lang_createtable.html).ÕâÒâζ×Å(ÖÁÉÙ)¶ÔÓÚ SQLLite À´Ëµ£¬ÕâÁ½¸öÓï¾ä»á×öÁ½¼þ²»Í¬µÄÊÂÇé.

                  According to the SQL Specification, a primary key can not contain NULL. This means that decorating a column with either "NOT NULL PRIMARY KEY" or just "PRIMARY KEY" should do the same thing. But you are relying on the SQL engine in question correctly following the SQL standard. As an example due to an early bug, SQL Lite does not correctly implement the standard and allows null values in non-integer primary keys (see sqlite.org/lang_createtable.html). That would mean for (atleast) SQLLite the two statements do two different things.

                  ÓÉÓÚNOT NULL PRIMARY KEY"Çå³þµØ±íÃ÷ÁËÒâͼ²¢ÇÒ¼´Ê¹Ö÷¼ü±»É¾³ýÒ²¼ÌÐøʹÓ÷ǿÕÖµ£¬ÕâÓ¦¸ÃÊÇÊ×Ñ¡Óï·¨.

                  As "NOT NULL PRIMARY KEY" clearly indicates intent and continues to enfore non-null values even if the primary key is removed, that should be the prefered syntax.

                  Õâƪ¹ØÓÚΪʲôҪʹÓá°·Ç¿ÕÖ÷¼ü"?ÔÚ TSQL ÖÐ?µÄÎÄÕ¾ͽéÉܵ½ÕâÁË£¬Ï£ÍûÎÒÃÇÍƼöµÄ´ð°¸¶Ô´ó¼ÒÓÐËù°ïÖú£¬Ò²Ï£Íû´ó¼Ò¶à¶àÖ§³Ö¸ú°æÍø£¡

                  ÉÏһƪ£ºÊý¾Ý¿âÉè¼Æ:Ò»ÕÅ´ó±í»¹Êǵ¥¶ÀµÄ±í? ÏÂһƪ£º×ÔÈ»¼üÓë´úÀí¼ü innodb Íâ¼ü

                  Ïà¹ØÎÄÕÂ

                      <bdo id='Gbl27'></bdo><ul id='Gbl27'></ul>
                  1. <i id='Gbl27'><tr id='Gbl27'><dt id='Gbl27'><q id='Gbl27'><span id='Gbl27'><b id='Gbl27'><form id='Gbl27'><ins id='Gbl27'></ins><ul id='Gbl27'></ul><sub id='Gbl27'></sub></form><legend id='Gbl27'></legend><bdo id='Gbl27'><pre id='Gbl27'><center id='Gbl27'></center></pre></bdo></b><th id='Gbl27'></th></span></q></dt></tr></i><div id='Gbl27'><tfoot id='Gbl27'></tfoot><dl id='Gbl27'><fieldset id='Gbl27'></fieldset></dl></div>
                  2. <tfoot id='Gbl27'></tfoot>

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

                      <legend id='Gbl27'><style id='Gbl27'><dir id='Gbl27'><q id='Gbl27'></q></dir></style></legend>