Changing the schema
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.
テーブル構造の変更
テーブルの設計は固定されていません。ALTER TABLE … ADD は既存のテーブルに新しいカラムを追加します:
ALTER TABLE product ADD weight DECIMAL(5, 2);
既存の行は、埋めるまで新しいカラムに NULL が割り当てられます。
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.
テーブルの削除
DROP TABLE はテーブル全体——構造とすべての行——を削除します:
DROP TABLE product;
これは取り消しができないため、注意して使用してください。他のテーブルが参照しているテーブルを削除すると、参照整合性が破損することがあります。
Common mistakes
ALTER TABLEadds or changes a column.- Existing rows get NULL in a new column unless you set a default.
よくあるミス
ALTER TABLEはカラムを追加または変更します。- デフォルトを設定しない限り、新しいカラムには既存の行に NULL が割り当てられます。
Add a new column weight of type DECIMAL(5, 2) to the product table using ALTER TABLE.
Click Run to see the output here. · 実行ボタンをクリックして出力を確認してください。
Delete the entire product table with DROP TABLE. (Afterwards only customer and orders remain.)
Click Run to see the output here. · 実行ボタンをクリックして出力を確認してください。