SFAH
SFAH

Reputation: 644

How to Change Default Null to NOT NULL in MySQL

I have the following column in table room Now I want to change the definition of column property_id from NULL to NOT NULL How can I do this following Query is not working

ALTER TABLE `room` CHANGE `property_id` `property_id` bigint(20)  NOT NULL;

Actual definition of Column is :

 `property_id` bigint(20) DEFAULT NULL,

Upvotes: 1

Views: 9607

Answers (2)

SFAH
SFAH

Reputation: 644

My Query was perfectly fine , The only mistake is that there are some rows that contains null record so that why it is creating an issue

Upvotes: 1

Sk. Irfan
Sk. Irfan

Reputation: 309

In mysql you can achieve this as,

ALTER TABLE room MODIFY property_id bigint(20) not null;

Upvotes: 3

Related Questions