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

This article was previously published under Q294445
This article has been archived. It is offered "as is" and will no longer be updated.
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.
Properties

Article ID: 294445 - Last Review: 11/02/2013 00:18:00 - Revision: 3.0

  • Microsoft SQL Server 7.0 Standard Edition
  • kbnosurvey kbarchive kbbug kbfix KB294445
Feedback