0

I am creating a database that has a table called tblOne Database Picture

I added a the column 'ID' and i forgot to disallow Nulls.

I am trying to change that with the query

    ALTER TABLE tblOne 
    ALTER COLUMN ID int NOT NULL;

I am seeing the following error:

Cannot insert the value NULL into column 'ID', table 'city.dbo.tblOne'; column does not allow nulls. UPDATE fails.

Ive used this query before. So I'm sure there is some small mistake I'm not seeing. The statement has been terminated.

Community
  • 1
  • 1
onTheInternet
  • 6,421
  • 10
  • 41
  • 74
  • possible duplicate of [How to add not null constraint to existing column in MySQL5.1](http://stackoverflow.com/questions/6305225/how-to-add-not-null-constraint-to-existing-column-in-mysql5-1) – xQbert Dec 11 '14 at 17:15
  • I've tried those suggestions. They dont work. – onTheInternet Dec 11 '14 at 17:20

1 Answers1

3

Cannot insert the value NULL into column 'ID', table 'city.dbo.tblOne'; column does not allow nulls. UPDATE fails.

By the sounds of it the table already contains data. With that column containing NULL's already. If you try to change the column to not allow nulls, but there is already a null value in, then the modification will fail. First change the data in that column so that it is not null, and then run your ALTER statement again

David-McQ
  • 164
  • 9