开发者

Not getting concept of null

Hy Guys,

Beginning with mysql. I am not able to grasp the concept of NULL. Check screen-shot (*declare_not_null, link*). In it when I specifically declared 'name' field to be NOT NULL. When i run the 'desc test' table command, the table description shows default value for name field to be NULL.Why is that so?

From what I have read about NULL, it connotes a missing or information that is not applicable. So when I declare a field to be NOT NULL it implies (as per my understanding) that user must enter a value for the name field else the DB engine should generate an error i.e. record will not be entered in DB. However when i run 'insert into test value();' the DB engine enters the record in table. Check screen-shot(*empty_value, link*).

FLICKR LINKS *开发者_运维知识库declare_not_null* http://www.flickr.com/photos/55097319@N03/5302758813/

*empty_values* Check the second screenshot on flickr

Q.2 what would be sql statemetn to drop a primary key from a table's field. If I use 'ALTER TABLE test drop key id;' it gives the following:

ERROR: Incorrect table definition; there can be only one auto column and it must be defined as a key.

Thanks for your help..


You are looking at the default value column. The database won't let you update or insert that column with null.


I'll take the first question:

When i run the 'desc test' table command, the table description shows default value for name field to be NULL.Why is that so?

The default being NULL means either:

  • You have specified that the default is NULL or
  • You haven't specified a default value for that column.

In this case it is the second option. It does not mean that it is possible to insert a NULL.


Q.1. I don't have access to Flickr so I can't see your screenshots, anyway, if you declare a column NOT NULL, there may be a default value for this column set, and that is why you can add a record.

Q.2. Looks like you cannot have an auto increment column that is not a Primary Key. So if you want to drop the Primary Key, you need to drop the auto increment first.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜