BUG: Primary Key Can Incorrectly Include a Nullable Column

Last reviewed: January 30, 1998
Article ID: Q180189
The information in this article applies to:
  • Microsoft SQL Server, version 6.5
BUG #: Windows NT: 17741 (6.5)

SYMPTOMS

If the "Columns Null by Default" option is selected for a database, the following CREATE TABLE statement will create a table with a nullable column included in the primary key:

   create table test(column1 varchar(12)
    CONSTRAINT mykey PRIMARY KEY (column1, column3),
   column2 varchar(2),
   column3 varchar(2))

This statement should not allow the primary key to have a nullable column. Either the primary key should be created with all columns defined as not null, or the following error message should be returned:

   Msg 8111, Level 16, State 0 Attempting to define PRIMARY KEY constraint
   on nullable column in table <table name>.

WORKAROUND

To work around this behavior, do either of the following:

  • Make sure the "Columns Null by Default" option is not selected.

    -or-

  • Define the primary key after all of the columns have been defined.

For example, the following CREATE TABLE statement will create a primary key without nullable columns regardless of whether or not the "Columns Null by Default" option is selected:

   create table test(column1 varchar(12),
   column2 varchar(2),
   column3 varchar(2),
   CONSTRAINT mykey PRIMARY KEY (column1, column3))

STATUS

Microsoft has confirmed this to be a problem in SQL Server version 6.5. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.


Additional query words: ANSI_NULL_DFLT_ON
Keywords : kbbug6.50 SSrvTran_SQL
Version : WINNT:6.5
Platform : winnt
Issue type : kbbug
Solution Type : kbworkaround


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: January 30, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.