Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I insert an empty string in a NOT NULL field?

Tags:

sql

Can I insert an empty string in a not null field?

insert into xyz(A,B) values(1,'');  // is this possible if B is NOT NULL?
like image 315
akshay Avatar asked Dec 30 '10 14:12

akshay


People also ask

What does empty string NOT NULL mean?

An empty string is a string instance of zero length, whereas a null string has no value at all. An empty string is represented as "" . It is a character sequence of zero characters.

Should I use empty string or NULL?

An empty string is useful when the data comes from multiple resources. NULL is used when some fields are optional, and the data is unknown.

How do you insert an empty value?

You also can specify the NULL keyword in the VALUES clause to indicate that a column should be assigned a NULL value. The following example inserts values into three columns of the orders table: INSERT INTO orders (orders_num, order_date, customer_num) VALUES (0, NULL, 123);

IS NULL same as empty string in MySQL?

NULL is used in SQL to indicate that a value doesn't exist in the database. It's not to be confused with an empty string or a zero value. While NULL indicates the absence of a value, the empty string and zero both represent actual values.


1 Answers

Yes you can... The concept of the NULL value is a common source of confusion for newcomers to SQL, who often think that NULL is the same as an empty string '', or a value of zero.

This is not the case. Conceptually, NULL means "a missing unknown value" and it is treated somewhat differently from other values. For example, to test for NULL, you cannot use the arithmetic comparison operators such as =, <, or <> in most DBMSes.

like image 78
Daniel Vassallo Avatar answered Sep 19 '22 16:09

Daniel Vassallo