development

null 값으로 열을 업데이트하는 방법

big-blog 2020. 6. 29. 07:31
반응형

null 값으로 열을 업데이트하는 방법


mysql을 사용하고 있으며 null 값으로 열을 업데이트해야합니다. 나는 이것을 여러 가지 방법으로 시도했으며 내가 얻은 최선은 빈 문자열입니다.

이를위한 특별한 구문이 있습니까?


특별한 문법은 없습니다 :

CREATE TABLE your_table (some_id int, your_column varchar(100));

INSERT INTO your_table VALUES (1, 'Hello');

UPDATE your_table
SET    your_column = NULL
WHERE  some_id = 1;

SELECT * FROM your_table WHERE your_column IS NULL;
+---------+-------------+
| some_id | your_column |
+---------+-------------+
|       1 | NULL        |
+---------+-------------+
1 row in set (0.00 sec)

NULLSQL에서 특별한 값입니다. 따라서 속성을 null로 설정하려면 다음을 수행하십시오.

UPDATE table SET column = NULL;

IS대신에 사용하면 =문제 예제 구문이 해결됩니다.

UPDATE studentdetails
SET contactnumber = 9098979690
WHERE contactnumber IS NULL;

열이 null 일 수 있는지 확인하십시오. 당신은 그것을 사용하여 할 수 있습니다

mysql> desc my_table;

열이 널이 될 수없는 경우 값을 널로 설정하면 캐스트 값이됩니다.

여기 예

mysql> create table example ( age int not null, name varchar(100) not null );
mysql> insert into example values ( null, "without num" ), ( 2 , null );
mysql> select * from example;
+-----+-------------+
| age | name        |
+-----+-------------+
|   0 | without num |
|   2 |             |
+-----+-------------+
2 rows in set (0.00 sec)

mysql> select * from example where age is null or name is null;
Empty set (0.00 sec)

비슷한 문제에 직면 한 사람들은 SET = NULL쿼리를 '시뮬레이션'할 때 PHPMyAdmin에서 오류가 발생 한다는 것을 알았습니다 . 붉은 청어입니다. 그냥 쿼리를 실행하면 모든 것이 잘됩니다.


위의 답변에서 여러 가지 방법과 반복이 동일하게 제안되었습니다. 언급 한 질문에 대한 답변을 계속 찾았지만 여기서 찾을 수 없었습니다.

그러나 위의 질문과 반대 인 "널 값으로 열 업데이트"는 "컬럼의 모든 로그를 NULL로 업데이트"일 수 있습니다.

그런 상황에서 다음 작품

update table_name
set field_name = NULL
where field_name is not NULL;

isis notmysql 에서도 작동합니다.


is대신에 사용=

예 : Select * from table_name where column is null


Another possible reason for the empty string, rather than a true null is that the field is an index or is part of an index. This happened to me: using phpMyAdmin, I edited the structure of a field in one of my tables to allow NULLs by checking the "Null" checkbox then hitting the "Save" button. "Table pricing has been altered successfully" was displayed so I assumed that the change happened -- it didn't. After doing an UPDATE to set all of those fields to NULL, they were, instead, set to empty strings, so I took a look at the table structure again and saw that the "Null" column for that field was set to 'no'. That's when I realized that the field was part of the Primary key!


If you want to set null value using update query set column value to NULL (without quotes) update tablename set columnname = NULL

However, if you are directly editing field value inside mysql workbench then use (Esc + del) keystroke to insert null value into selected column


if you follow

UPDATE table SET name = NULL

then name is "" not NULL IN MYSQL means your query

SELECT * FROM table WHERE name = NULL not work or disappoint yourself


I suspect the problem here is that quotes were entered as literals in your string value. You can set these columns to null using:

UPDATE table SET col=NULL WHERE length(col)<3;

You should of course first check that these values are indeed "" with something like:

SELECT DISTINCT(col) FROM table WHERE length(col)<3;

참고URL : https://stackoverflow.com/questions/3870540/how-to-update-column-with-null-value

반응형