I'm designing database and I'm curious about does mandatory checkbox in mysql workbench mean, that field should be null or to what does mandatory in this situation refer?
Later if necessary I will include an image of this table where this question occurred.
Tanks every on for help.
UPD:
I must say, that after I generated models SQL and looked at both tables I didn't see anything different. I'm starting to think, that this mandatory option is displayed only visually, but in functional way it doesn't mean anything.
If I'm wrong someone please help. Tanks again.
In MySQL Workbench, right click on the cell and select 'Set Field to NULL'. In MySQL Workbench this setting is now called Set Field(s) to NULL , and is the first option in the list.
You can set MySQL to strict mode to force valid values. This will reject a query that does not provide a value for a NOT NULL column as well as enforce integrity on all types of columns. Update: MySQL 5.7 and above now have strict mode on by default.
To search for column values that are NULL , you cannot use an expr = NULL test. The following statement returns no rows, because expr = NULL is never true for any expression: mysql> SELECT * FROM my_table WHERE phone = NULL; To look for NULL values, you must use the IS NULL test.
If a data type specification includes no explicit DEFAULT value, MySQL determines the default value as follows: If the column can take NULL as a value, the column is defined with an explicit DEFAULT NULL clause. If the column cannot take NULL as a value, MySQL defines the column with no explicit DEFAULT clause.
Ok, I found it.
Let's say you have one table called User
and a second called Address
and you want to make a relation between them. The example might look like this:
User
id
NameAddress
id
user_id
street
So you have a foreign key in Address
for the User
. If you make this relation, all fields are mandatory, so user_id
is a primary key field it is not null, and Address
-id
is even the same, but what is Address
-user_id
? Is it really a part of primary key in Address
? No, it doesn't help you to identify a row in this table. So the Address
-user_id
could be null, maybe you only got an Address
or the table Address
is even referenced by a table company.
The thing is, the mandatory checkbox on the "Referencing Table"-side is only for visual effects, on the opposite the checkbox on the "Referenced Table"-side makes the field nullable or not.
If mandatory, the field Address-user_id never could be null. If not mandatory, the field can be null for one row of data and no constrained will be affected.
I came to a conclusion that this is just a visual effect to show, that the relationship is mandatory. This option doesn't affect the generated SQL code in anyway.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With