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. · اضغط تشغيل لرؤية المخرجات هنا.