Add a NOT NULL constraint to the column

I am using PHPMyAdmin and I am trying to add a NOT NULL constraint to the column of my table.

PHPMyAdmin accepts my following request:

ALTER TABLE `wall` MODIFY `token_message` varchar(40) NOT NULL;

But I can still insert blank lines (= NULL), I don't understand why.

PS: If you want to give me other requests to add this restriction, please note that I tried these 3, which do not work in my PHPMyAdmin (error type: # 1064 - You have an error in your SQL syntax, check the manual):

ALTER TABLE `wall` ALTER COLUMN `token_message` SET NOT NULL;
ALTER TABLE `wall` ALTER COLUMN `token_message` varchar(40) NOT NULL;
ALTER TABLE `wall` MODIFY `token_message` CONSTRAINTS token_message_not_null NOT NULL; 
+3
source share
4 answers

: " (= NULL)", . SQL NULL . SELECT from wall where token_message is NULL. . , NULL (unquoted) , .

, , , , . .

+5

MySQL , . , :

ALTER TABLE wall MODIFY token_message varchar(40) NOT NULL default ''

"SET" - .

ref: http://dev.mysql.com/doc/refman/5.1/en/alter-table.html

+2

, . , ('') NULL sql. - , , :

CREATE PROC InsertIntoMyDb (@MyVarChar VARCHAR(2000)) AS

SET @MyVarChar = NULLIF(RTRIM(LTRIM(@MyVarChar)), '')

INSERT INTO [TBL] (MyVarChar)
VALUES @MyVarChar

, NULL, NULL , .

0

Alter table table_name 
change column_name column_name datatype(length) definition


Alter table wall 
change tocken_message tocken_message varchar(40) NOT NULL DEFAULT
0

All Articles