MySQL: NOT NULL constraint

preview_player
Показать описание
#MySQL #course #tutorial

CREATE TABLE products (
product_id INT,
product_name varchar(25),
price DECIMAL(4, 2) NOT NULL
);

ALTER TABLE products
MODIFY price DECIMAL(4, 2) NOT NULL;

INSERT INTO products
VALUES(104, "cookie", NULL);
Рекомендации по теме
Комментарии
Автор

CREATE TABLE products (
product_id INT,
product_name varchar(25),
price DECIMAL(4, 2) NOT NULL
);

ALTER TABLE products
MODIFY price DECIMAL(4, 2) NOT NULL;

INSERT INTO products
VALUES(104, "cookie", NULL);

BroCodez
Автор

Thank you so much. Love all your lessons

derrickndi
Автор

Thanks for the explanation. I was using google bard but it just gave me a complex break down which made me confused asf. Im very new to datamanagement.

Othjkdzv
Автор

can i use ADD CONSTRAINT instead of MODIFY ? IF NOT THEN WHY?

saimoomsikto
Автор

Hi bro, When you set a parameter not to accept NULL values and you put " " instead of a value or set of characters, it does not return an error. Please clarify this.

patrickmuthengi