Calflamesfann
Calflamesfann

Reputation: 143

Strange error upon insert in SQL

This process is part of one where I take fields from a 96 column table and place them in a 26 column table (directory). Yrqtr is a field in the table, equi.

I am getting the following error message. I am only confused because yrqtr is not in either statement. any ideas why this one is coming up?

Msg 515, Level 16, State 2, Line 1 Cannot insert the value NULL into column 'yrqtr', table 'wid27.dbo.directory'; column does not allow nulls. INSERT fails.

   Insert into dbo.directory(state,account,unit,name1,name2,address1,address2,city,st,zip,zipext,addressty,geo1,geo2,telephone,employment,ownership,naicscode,siccode,area)

   Select state,account,unit,name1,name2,address1,address2,city,st,zip,zipext,addressty,geo1,geo2,telephone,employment,ownership,naicscode,siccode,area
   From dbo.equi Where something !=2

Upvotes: 0

Views: 23

Answers (1)

Taylor Ackley
Taylor Ackley

Reputation: 1437

That would be a constraint in your table schema.

If you look at your schema you will most likely see NOT NULL next to the column definition. If you remove it, you will be able to insert. However, you could be breaking someone else's intentional schema design and inserting a null value could lead to bugs.

More information:

https://www.w3schools.com/sql/sql_notnull.asp

Upvotes: 1

Related Questions