English 中文(简体)
MySQL 为何允许将非 NULL 列更新到 NULL?
原标题:Why does MySQL allow to update a NOT NULL column to NULL?
  • 时间:2012-05-22 13:15:02
  •  标签:
  • mysql

我在 ubuntu 10.10 中运行 MySql 。我创建了一个名为 雇员的表格 ,该表格有3个外名 < enger > emmpno, 名称和工资 。插入了几个实体。在程序中间,我想将工资属性更改为 NULL

ALTER TABLE employee MODIFY salary int(10) NOT NULL;

查询被执行。 我想通过使用命令来测试,

UPDATE employee SET salary=NULL;

Query OK, 15 rows affected, 15 warnings (0.06 sec)
Rows matched: 15  Changed: 15  Warnings: 15

还给出警告 (Code 1048): 列工资不能为空 " (每行重写)

但当我看到我的表时, 所有的工资都是零(0 )。

在 WINDOWS XP 的 MySql 中, < strong> 相同查询导致错误, 而不是警告

I checked in both INNODB and MYISAM engines but same Result. Please help me to know what happened beside processing.

最佳回答

您必须没有设置对 Ubuntu 安装严格严格的 SQL_MODE 设置 。

问题 议题

SET SQL_MODE= STRICT_ALL_TABLES 

或添加

SQL_MODE= STRICT_ALL_TABLES 

[mysqld] 下, my.cnf 下有 Ubuntu

问题回答

我看不出问题所在, 您将列设置为 < code> NOT NULL (不允许 NULL 值), 现在它不会允许您设置为 < code> NULLL , 这将是预期的行为 。

您在 DB 中有 0 秒的原因是, 0 是将 NULL 投入一整点的结果 。





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签