Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL. Changes require the table to be recreated

There is a table full which contains data. Is it possible to change field from [not null] to [null] without dropping and recreating it? SQL writes that table have to be dropped and recreated. :)

like image 211
Anton Lyhin Avatar asked Oct 19 '25 09:10

Anton Lyhin


1 Answers

You can try:

alter table YourTable alter column YourColumn int null

Per Martin Smiths comment, a change in nullability does not require a copy of the table. On disk, each row has a nullabiltiy bitmap at the start. I thought the bitmap had to be resized in some cases, but apparently it contains a bit for each column, nullable or not nullable.

like image 187
Andomar Avatar answered Oct 22 '25 01:10

Andomar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!