Sobes.tech
Junior — Middle

Milliseid andmebaasi tabelite muutmise meetodeid teate?

sobes.tech AI

Vastus AI-lt

To modify database tables, SQL DDL (Data Definition Language) commands are typically used. The main methods:

  • 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 appropriate SQL queries to the database.