Changing the schema · Alterando o esquema
Changing a table's structure
A table's design is not fixed. ALTER TABLE … ADD adds a new column to an existing table:
Existing rows get NULL in the new column until you fill them in.
Alterando a estrutura de uma tabela
O design de uma tabela não é fixo. ALTER TABLE … ADD adiciona uma nova coluna a uma tabela existente:
ALTER TABLE product ADD weight DECIMAL(5, 2);
As linhas existentes recebem NULL na nova coluna até você preenchê-las.
Removing a table
DROP TABLE deletes a whole table — its structure and all its rows:
This cannot be undone, so use it with care. Dropping a table that other tables reference can break referential integrity.
Removendo uma tabela
DROP TABLE exclui toda uma tabela — sua estrutura e todas as suas linhas:
DROP TABLE product;
Isso não pode ser desfeito, então use com cuidado. Excluir uma tabela que outras tabelas referenciam pode quebrar a integridade referencial.
Common mistakes
ALTER TABLEadds or changes a column.- Existing rows get NULL in a new column unless you set a default.
Erros comuns
ALTER TABLEadiciona ou altera uma coluna.- Linhas existentes recebem NULL em uma nova coluna a menos que você defina um padrão.
Add a new column weight of type DECIMAL(5, 2) to the product table using ALTER TABLE. · Adicione uma nova coluna weight do tipo DECIMAL(5, 2) à tabela product usando ALTER TABLE.
Click Run to see the output here. · Clique em Executar para ver a saída aqui.
Delete the entire product table with DROP TABLE. (Afterwards only customer and · e orders remain.) · Apague a tabela inteira product com DROP TABLE. (Depois restarão apenas customer e orders.)
Click Run to see the output here. · Clique em Executar para ver a saída aqui.