- DELETE FROM TABLE
- INSERT INTO TABLE
- TRUNCATE TABLE
DELETE FROM TABLE
Removes rows from the specified table. You can use theWHERE clause to specify the rows to remove. If a DELETE SQL statement lacks the WHERE clause, then the database deletes all rows in the table.
To use this statement, you must have the DELETE privilege for the table.
For details and examples, see Remove Records from an Ocient System.
DELETE actions cannot be undone.If a DELETE operation fails during execution, the database rolls back the changes and returns to its original state.Due to limitations of the JDBC API, the reported modified row count might not be accurate for
DELETE operations that are larger than two billion rows.SQL
Examples
Delete Rows from the Table with Filter Criteria
This
DELETE SQL statement removes all rows in the movies table that have a budget of less than 10000.
SQL
WITH keyword to find rows representing all transactions that occurred before 2022 that are less than $100. The DELETE SQL statement receives the results from the common table expression. Then, the database executes this statement to delete the corresponding rows.
SQL
INSERT INTO TABLE
INSERT INTO inserts rows into a table in the current database using literal values, column references, function executions, computed expressions, or column default values.
This SQL statement requires the INSERT privilege for the relevant table.
Due to limitations of the JDBC API, the reported modified row count might not be accurate for insert operations that are larger than two billion rows.
SQL
Using
DEFAULT VALUES inserts a single row where each target column is populated with its column defaults (as defined in the column definition) instead of an explicit VALUES list.For table columns that do not each have a defined default value, the inserted row is NULL. If the column has no default and also has the NOT NULL constraint, the insert operation generates an error.
Examples
Insert Values from One Column
This example inserts the columns from
system.table_b into system.table_a.
SQL
system.table_b.id_col_b into system.table_a.id_col_a and system.table_b.int_col_b into system.table_a.int_col_a.
SQL
product— Product identifierquantity— Quantity of the product soldsale_date— Date of sale
SQL
SQL
sales table before inserting rows into the monthly_sales_summary table.
The example uses the monthly_sales_summary table created by this CREATE TABLE statement with these non-nullable columns:
product_id— Product identifiermonth— Month part of the datetotal_quantity— Total quantity of the product
SQL
WITH keyword extracts the month from the sale date sale_date and calculates the sum of the quantity sold total_quantity of the product from the sales table before inserting this data. Then, the INSERT SQL statement specifies to insert the data into the monthly_sales_summary table.
SQL
customers table with these columns:
customer_id— Customer identifiername— Customer namestatus— Customer status with the defaultactivestatuscreated_at— Created date
SQL
DEFAULT VALUES keyword to insert one row of default values into the table. For columns that lack a defined default value, the operation inserts a NULL row.
SQL
status column, which has the active default value.
SQL
SQL
DEFAULT keyword as one of the row values in the INSERT statement.
SQL
SQL
INSERT INTO TABLE USING LOADERS
Specify one or more Loader Nodes for executing theINSERT INTO SQL statement. If you do not use this option, the Ocient System uses all Loader Nodes that are live to execute the SQL statement.
This statement is useful for managing loading operations, particularly when balancing multiple loads of different sizes and resource requirements. Alternatively, this statement can also help simplify small batch loads by sourcing the data from a single Loader Node.
Syntax
SQL
For the query to execute successfully, the specified names must:
- Identify nodes that are live.
- Identify nodes that have the Loader role.
system.table_b.id_col_b into system.table_a.id_col_a and system.table_b.int_col_b into system.table_a.int_col_a. Use the Loader Node named stream-loader1 to execute this SQL statement.
SQL
stream-loader2 and stream-loader3.
SQL
TRUNCATE TABLE
TRUNCATE TABLE removes some or all records from an existing table in the current database. The system deletes the truncated data, but the table and its schema remain intact in the system even if all data is deleted. If the entire table is truncated, Global Dictionary Compression tables remain in place.
To truncate a table, you must have the DELETE privilege for the table.
To remove a subset of rows from a table, you can use the DELETE FROM TABLE SQL statement.
For details and examples of using TRUNCATE, see Remove Records from an Ocient System.
Syntax
SQL
Examples
This example truncates an existing table in the current database and schema named
students.
SQL
us.students.
SQL
students.
SQL
us.students.
SQL

