Changing the schema · Cambiar el 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.
Cambiar la estructura de una tabla
El diseño de una tabla no es fijo. ALTER TABLE … ADD agrega una nueva columna a una tabla existente:
ALTER TABLE product ADD weight DECIMAL(5, 2);
Las filas existentes obtienen NULL en la nueva columna hasta que las rellenes.
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.
Eliminar una tabla
DROP TABLE elimina toda una tabla — su estructura y todas sus filas:
DROP TABLE product;
Esto no se puede deshacer, así que úsalo con cuidado. Eliminar una tabla a la que otras hacen referencia puede romper la integridad referencial.
Common mistakes
ALTER TABLEadds or changes a column.- Existing rows get NULL in a new column unless you set a default.
Errores comunes
ALTER TABLEagrega o modifica una columna.- Las filas existentes obtienen NULL en una nueva columna a menos que establezcas un valor predeterminado.
Add a new column weight of type DECIMAL(5, 2) to the product table using ALTER TABLE. · Agregar una nueva columna weight de tipo DECIMAL(5, 2) a la tabla product usando ALTER TABLE.
Click Run to see the output here. · Haz clic en Ejecutar para ver la salida aquí.
Delete the entire product table with DROP TABLE. (Afterwards only customer and · y orders remain.) · Eliminar toda la tabla product con DROP TABLE. (Después solo quedan customer y orders.)
Click Run to see the output here. · Haz clic en Ejecutar para ver la salida aquí.