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. · הוסיפו עמודה חדשה weight מסוג DECIMAL(5, 2) לטבלת הproduct באמצעות ALTER TABLE.
Click Run to see the output here. · לחץ על הרץ כדי לראות את התוצא כאן.
Delete the entire product table with DROP TABLE. (Afterwards only customer and orders remain.) · מחקו את כל הטבלה product באמצעות DROP TABLE. (לאחר מכן נותרו רק הcustomer והorders.)
Click Run to see the output here. · לחץ על הרץ כדי לראות את התוצא כאן.