Updated on 2024-05-07 GMT+08:00

Deleting Data from a Table

Outdated data may need to be deleted when tables are used. Data can be deleted from tables only by row.

SQL statements can only access and delete an independent row by declaring conditions that match the row. If a table has a primary key, you can use it to specify a row. You can delete several rows that match the specified condition or delete all the rows from a table.

For example, delete all the rows whose c_customer_sk column is 3869 from the table customer_t1.

1
gaussdb=# DELETE FROM customer_t1 WHERE c_customer_sk = 3869;

To delete all rows from the table, run either of the following commands:

1
gaussdb=# DELETE FROM customer_t1;

Or

1
gaussdb=# TRUNCATE TABLE customer_t1;

If you need to delete an entire table, you are advised to use the TRUNCATE statement rather than DELETE.

Delete the created table.

1
gaussdb=# DROP TABLE customer_t1;