-1

I'm having issues here.

    use WRC_temp;
    alter table dbo.WRC_Readers
    alter column ReaderID varchar(50) not null

And I keep getting this error.

Msg 515, Level 16, State 2, Line 2
Cannot insert the value NULL into column 'ReaderID', table     'WRC_temp.dbo.WRC_Readers'; column does not allow nulls. UPDATE fails.
The statement has been terminated.

I can't seem to understand. If Anyone can help, I'd appreciate it. :)

1 Answers1

0

I am guessing that your table is NOT empty and there are some rows currently existing in the table. When you add the 'Not Null' constraint to the column, the existing data fails to pass the new constraint.

There are several ways to address this problem. this should be the easiest one:

Apply the schema change in multiple steps: 1) Update the existing rows and assign a value to ReaderId column where ReaderId is null For example: Update dbo.WRC_Readers Set ReaderID = 0 Where ReaderID is null 2) Run your alter table statement

Sparrow
  • 2,548
  • 1
  • 24
  • 28