Not getting the concept of null

Hy Guys,

Starting with mysql. I can not understand the concept of NULL. Check out the screenshot (* declare_not_null, link *). In this case, when I specifically declared the name field so that it was NOT NULL. When I run the desc test table command, the table description shows the default value for the NULL name field. Why is this so?

From what I read about NULL, this means the absence or information that is not applicable. Therefore, when I declare a NOT NULL field, it implies (according to my understanding) that the user must enter a value for the name field, otherwise the database engine must generate an error, that is, the record will not be entered into the database. However, when I run 'insert into test value ();' the database engine enters the record into the table. Check out the screenshot (* empty_value, link *).

LINKS FLICKR * Declare_not_null * http://www.flickr.com/photos/ 55097319 @ N03 / 5302758813 /

* empty_values ​​* Check out the second screenshot on flickr

Q.2, what would sql statemetn be to remove the primary key from the table field. If I use "ALTER TABLE test drop key id"; he gives the following:

Error: Invalid table definition; there can only be one automatic column, and it must be defined as a key.

Thank you for your help.

+3
source share
3 answers

You are viewing a column of default values. The database will not allow you to update or insert this column with null.

+1
source

I will take the first question:

When I run the desc test table command, the table description shows the default value for the NULL name field. Why is this so?

The default value of NULL means either:

  • You indicated that the default value is NULL or
  • You did not specify a default value for this column.

In this case, this is the second option. This does not mean that you can insert NULL.

+1

Q.1. Flickr, , , NOT NULL, , .

IN 2. It looks like you cannot have an auto-increment column that is not a Primary Key. Therefore, if you want to reset the primary key, you must first cancel the auto-increment.

0
source

Source: https://habr.com/ru/post/1782597/


All Articles