0

I'm getting the "String or binary data would be truncated" error when trying to insert integers to one of my tables.

I've read several post about the length of the column vs the length of the value one is inserting, but it doesn't seem to be my case once the columns are all int or smallint type and the values are all maximum two digits.

The table structure is the following:

CREATE TABLE [tblvUserLocation] (
    [User_Location_ID] [int] IDENTITY (1, 1) NOT NULL ,
    [Location_ID] [int] NULL ,
    [Line_Type_ID] [int] NULL ,
    [User_ID] [int] NULL ,
    [Active] [smallint] NULL CONSTRAINT [DF_tblvUserLocation_Active] DEFAULT (1),
    [Last_Updated] [smalldatetime] NULL CONSTRAINT [DF_tblvUserLocation_Last_Updated] DEFAULT (getdate()),
    [Last_Updated_By] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL CONSTRAINT [DF_tblvUserLocation_Last_Updated_By] DEFAULT (suser_sname())
) ON [PRIMARY]
GO

The insert I'm trying to run is the following:

insert into tblvUserLocation (Location_ID, Line_Type_ID, [User_ID], Active)
values (20, 2, 41, 1)

And the error I'm getting is the following:

Server: Msg 8152, Level 16, State 2, Line 1 String or binary data would be truncated. The statement has been terminated.

If that makes any difference, I'm using SQL Server 2000.

Please let me know what your thoughts are.

Thanks!

2
  • 1
    You know, it really is beyond time that you considered upgrading. You're 5 (and a half, if you count 2008 R2) versions behind the current latest. Even extended support for the product ended over three years ago. (And, in fact, even extended support for 2005 ended this year) Jun 16, 2016 at 14:47
  • You know, it really is beyond my power of choice. The company has applications running in legacy technology, I'm just doing my job. But thanks for the useless comment anyway (: Jun 16, 2016 at 15:48

1 Answer 1

4

Looks like the problem comes from your [DF_tblvUserLocation_Last_Updated_By] constraint.

It's pulling the current username which is more than likely longer than the length of your [Last_Updated_By] column VARCHAR(10).

Update your DDL to:

[Last_Updated_By] [varchar] (128)
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.