在這個表中,我希望標題列在插入或更新行時不允許爲null(不能爲空)... 。用戶應該100%插入一些值,以便生成該行。mysql,更新後的列會得到空值,如何在插入和更新時不允許爲空
create table tab(id int not null auto_increment
primary key,
title varchar(255) not null);
+-------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| title | varchar(255) | NO | | NULL | |
+-------+--------------+------+-----+---------+----------------+
創建表。
我現在插入:
插入到標籤(id
,title
)值(1, 'TITLE1'); ..... true
insert into tab(id
)value(2); ......................... true --- - 這不應該是null。
mysql> select * from tab;
+----+--------+
| id | title |
+----+--------+
| 1 | title1 |
| 2 | |
+----+--------+
2 rows in set (0.00 sec)
null或空字符串?也許你應該刪除默認值 – Uriil
我怎麼可以使一列表不爲空,當用戶插入數據時,如果不是它只是給出錯誤和回滾,則應該使用100%的值。 – SAR