Junior — Middle
What commands can modify the structure of a table in SQL?
sobes.tech AI
Answer from AI
To modify the structure of a table in SQL, the ALTER TABLE command is used. With it, you can:
- Add new columns:
ALTER TABLE table_name ADD column_name datatype; - Drop columns (in some DBMS):
ALTER TABLE table_name DROP COLUMN column_name; - Change the data type of a column:
ALTER TABLE table_name MODIFY column_name new_datatype; - Rename columns or tables (depends on the DBMS)
Example:
ALTER TABLE employees ADD salary DECIMAL(10,2);
ALTER TABLE employees DROP COLUMN age;
ALTER TABLE employees MODIFY salary FLOAT;