Any explanation for this SQL?

Asked

Viewed 48 times

-1

$alters = " ALTER TABLE imovel
  MODIFY COLUMN ENDERECO VARCHAR(150),
  MODIFY COLUMN BAIRRO VARCHAR(150)";
$pdo->exec($alters);

As I decrease the varchar value, it updates, but if I increase the varchar value no longer works.

Any explanation?

1 answer

1


You can unite all MODIFY:

ALTER TABLE imovel
  MODIFY (ENDERECO VARCHAR(150),
          BAIRRO VARCHAR(150)
          );

NOTE: I don’t know if it is compatible with Mysql above!

But, you can also remove the "COLUMN" parameter, for Mysql:

ALTER TABLE imovel
  MODIFY ENDERECO VARCHAR(150),
  MODIFY BAIRRO VARCHAR(150);

As far as I know, the only one who has "[FUNÇÃO] COLUMN nome_da_coluna" is the DROP, this is "DROP COLUMN".

But everything else is MODIFY nome_da_coluna and ADD nome_da_coluna, without including the COLUMN in the name of the function.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.