Microsoft KB Archive/294445

From BetaArchive Wiki
Knowledge Base


FIX: Error Message 2731 Occurs When You Create a Table with a Column Length of Zero

Article ID: 294445

Article Last Modified on 3/14/2006



APPLIES TO

  • Microsoft SQL Server 7.0 Standard Edition



This article was previously published under Q294445

BUG #: 54532 (SQLBUG_70)

SYMPTOMS

In Microsoft SQL Server 6.5, the following query executes successfully:

select col1='', au_id into #abc from pubs..authors
                

In SQL Server 7.0 versions prior to Service Pack 2 (SP2), the preceding query incorrectly executes successfully.

In SQL Server 7.0 SP2, or later, executing the preceding statement results in this error message:

Server: Msg 2731, Level 16, State 1, Line 1
The width of column 'col1' is 0. This width is not valid.

CAUSE

In SQL Server 6.5, empty strings are treated as single spaces. The statement in the "Symptoms" section creates a table in which the first column has a length of one.

In SQL Server 7.0 versions prior to SP2, empty strings are treated as empty strings and the preceding statement creates a table in which the first column has a length of zero. This is not expected behavior. The column size must require at least 1 byte.

STATUS

Microsoft has confirmed this to be a problem in SQL Server 7.0. This problem has been corrected in U.S. Service Pack 2 for Microsoft SQL Server 7.0. For more information, click the following article number to view the article in the Microsoft Knowledge Base:

254561 INF: How to Obtain Service Pack 2 for Microsoft SQL Server 7.0 and Microsoft Data Engine (MSDE) 1.0


For more information, contact your primary support provider.

MORE INFORMATION

In SQL Server 7.0 SP2, and later, you do not get the error message when you set the compatibility level (sp_dbcmptlevel) of the database to 60 or 65. The compatibility level setting causes SQL Server to interpret the empty strings as single spaces and creates a varchar column of length 1 instead of a column length of zero.

Keywords: kbbug kbfix KB294445