Learn more. How to update column with null value Ask Question. Asked 11 years, 3 months ago. Active 1 year, 1 month ago. Viewed k times. Is there a special syntax to do this? Improve this question. Does the column allow a NULL value?
No, not at all. It's really wierd — jim. Add a comment. Active Oldest Votes. Improve this answer. Daniel Vassallo Daniel Vassallo k 70 70 gold badges silver badges bronze badges.
Thanks Daniel. I'm kind of convinced that this issue may lie in my application code — jim. Gumbo Gumbo k gold badges silver badges bronze badges. Now, let me clarify. Through php I am using PDO and updating through a query.
I've checked it twice. Let me look one more time. Yes, it is in fact null. I can see the NULL produced by my frnt end software in the data that should be null. Find centralized, trusted content and collaborate around the technologies you use most.
Connect and share knowledge within a single location that is structured and easy to search. If you want to alter the table structure by changing columns so that they no longer accept nulls, you could do it with a stored procedure. From that information, it builds up a prepared statement which is then used to alter the table structure.
The following line displays the command that is to be executed, and may be removed from the stored procedure if necessary:. You can do this in a single statement, as per MySQL documentation :. Not without an intermediate technology or cursor. So it is possible. But by the time it took you to write that, you probably just could have copy and pasted ;.
I don't believe there is; any statement that worked on rows that didn't satisfy the where clause would update rows you didn't intent to update. Jason's answer is correct, but, I think, a bit unsafe, unless you are really sure that's what you want. Note: If you are trying to set your values '0' instead of an empty string if a column's datatype is int.
Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Asked 11 years, 6 months ago. Active 3 years, 2 months ago. Viewed 35k times. I'd like to update all NULL fields in one table to 0. Be sure it's hitting the tables that you really need.
Last thing you want to do is update something you didn't mean to with this. John Mitchell COLUMNS instead of syscolumns, since it doesn't rely on system tables, which may change from version to version or even service pack to service pack. And don't forget to include a check for column nullability, since you'll get an error if you try to set a value to NULL in a non-nullable column. You must be logged in to reply to this topic.
Login to reply.
0コメント