Delete a column in BigQuery
In BigQuery, we can remove one or more columns from an existing table using the ALTER TABLE … DROP COLUMN statement. This operation modifies the table schema and does not require recreating the table.
SQL Syntax
ALTER TABLE table_name DROP COLUMN [IF EXISTS] column_name [, ...];
Arguments:
- table_name: The name of the table to alter.
- IF EXISTS: If the specified column does not exist, the statement has no effect.
- column_name: The name of the column to drop.
Example: Drop a single column from a table.
SQL
ALTER TABLE `ashishcoder.Coding_Dataset.clustered_table` DROP COLUMN IF EXISTS total_amount;
Dropping Multiple Columns at Once
We can drop more than one column in a single ALTER TABLE statement.
SQL
ALTER TABLE `ashishcoder.Coding_Dataset.clustered_table` DROP COLUMN IF EXISTS discount, DROP COLUMN IF EXISTS tax;