Junior — Middle
What methods of modifying database tables do you know?
sobes.tech AI
Answer from AI
SQL Data Definition Language (DDL) commands are typically used to modify database tables. Main methods include:
-
ALTER TABLE — allows changing the structure of a table: adding, removing, or modifying columns, changing data types, adding or removing constraints.
-
CREATE TABLE — creating a new table.
-
DROP TABLE — deleting a table.
-
RENAME TABLE — renaming a table (in some DBMS).
Example of adding a column:
ALTER TABLE employees ADD COLUMN birthdate DATE;
Example of changing a column's data type:
ALTER TABLE employees ALTER COLUMN salary TYPE DECIMAL(10,2);
In Java, such operations are usually performed using JDBC, by sending the corresponding SQL queries to the database.