Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I want to insert data into the zipcode column of the employee3 table. SQL says write - INSERT INTO Employee3 (ZipCode) VALUES (28279);, however I keep getting this error message:

Msg 515, Level 16, State 2, Line 1
Cannot insert the value NULL into column 'EMPLOYEEID', table
'AdventureWorks2012.dbo.EMPLOYEE3'; column does not allow nulls. 

INSERT fails.

I understand other columns have "NOT NULL" CONSTRAINTS, but I only want to INSERT data to the ZipCode column. Is there anyway around having to update the other columns?

share|improve this question
3  
You don't "insert data into a column". You "insert a row (or rows) into a table". –  evilcube Jul 8 '14 at 16:25
1  
I'm pretty sure you want to use an UPDATE statement here, not INSERT. If that's the case, please remember to use a WHERE clause in that statement so it only puts the data exactly where you need it to go. –  Jon Seigel Jul 8 '14 at 17:31

2 Answers 2

Nope, you'll need to provide values for the columns which are listed as NOT NULL.

share|improve this answer

You cannot insert a row without specifying values for columns that have NOT NULL constraints. What would be the point of having NOT NULL constraints on those columns if it wasn't enforced?

You would need to remove the NOT NULL constraint clause for each column in the table in order to insert a row that only contains the Zip code value.

This begs the question: Are you really trying to insert a row that ONLY has a zip code, and nothing else? Or are you actually trying to modify the zip code for already existing rows in the table? If that is the case, you need to use an UPDATE <TABLE> statement, not an INSERT INTO statement.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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