DB2 Tutorial

  • Home
  • Start Here
  • Basics
  • Views
  • Triggers
  • Indexes
  • Functions
    • Aggregate Functions
    • Date Functions
    • String Functions
    • Window Functions
Home » Db2 Basics » Db2 ALTER TABLE DROP COLUMN

Db2 ALTER TABLE DROP COLUMN

Summary: in this tutorial, you’ll learn how to drop one or more columns in a table by using the Db2 ALTER TABLE DROP COLUMN statement.

Introduction to Db2 ALTER TABLE DROP COLUMN statement

Sometimes, you may want to delete one or more unused columns from a table. To do this, you use the ALTER TABLE DROP COLUMN statement as follows:

ALTER TABLE table_name DROP COLUMN column_name;

In this syntax:

  • First, specify the name of the table from which you want to drop the column in the ALTER TABLE clause.
  • Second, specify the name of the column that you want to delete in the DROP COLUMN clause.

To delete multiple columns, you can use the following syntax:

ALTER TABLE table_name DROP COLUMN column_name_1 DROP COLUMN column_name_2 ...;

Note that there is no comma between the DROP COLUMN clauses.

Db2 ALTER TABLE DROP COLUMN examples

We’ll use the orders table created in the ALTER TABLE tutorial for the demonstration.

db2 alter table drop column sample table

1) Dropping one column example

The following example removes the note column from the orders table:

ALTER TABLE orders DROP COLUMN note;

To verify the change, you can use the DESCRIBE TABLE command:

DESCRIBE TABLE orders;

Here is the output:

db2 drop one column example

The note column has been dropped.

2) Dropping multiple columns example

This example uses the ALTER TABLE DROP COLUMN to drop the requested_date and order_status columns:

ALTER TABLE orders DROP COLUMN requested_date DROP COLUMN order_status;

The following picture shows the column list of the orders table after executing the above statement:

DESCRIBE TABLE orders;
db2 drop multiple columns example

In this tutorial, you’ve learned how to drop one or more unused columns from a table by using the Db2 ALTER TABLE DROP COLUMN statement.

  • Was this tutorial helpful ?
  • YesNo
Previous Db2 ALTER TABLE ALTER COLUMN
Next Db2 DROP TABLE

Getting Started

  • What is Db2
  • Installing Db2 Database Server
  • Db2 Sample Database
  • Creating a Db2 Sample Database
  • Connecting to a Db2 Database
  • Interacting with Db2 using SQL Developer

Data Manipulation

  • SELECT
  • ORDER BY
  • WHERE
  • SELECT DISTINCT
  • AND
  • OR
  • BETWEEN
  • LIKE
  • IN
  • LIMIT
  • FETCH
  • Join
  • INNER JOIN
  • LEFT JOIN
  • RIGHT JOIN
  • FULL OUTER JOIN
  • Self-Join
  • CROSS JOIN
  • GROUP BY
  • Subquery
  • HAVING
  • UNION
  • INTERSECT
  • EXCEPT
  • Common Table Expression or CTE
  • INSERT
  • INSERT Multiple Rows
  • INSERT INTO SELECT
  • UPDATE
  • DELETE

Managing Database Objects

  • CREATE TABLE
  • Identity Columns
  • ALTER COLUMN
  • ADD COLUMN
  • DROP COLUMN
  • DROP TABLE
  • TRUNCATE TABLE
  • RENAME TABLE

Db2 Constraints

  • Primary Key
  • Foreign Key
  • DEFAULT
  • NOT NULL
  • CHECK
  • UNIQUE

Db2 Data Types

  • Integer
  • Decimal
  • VARCHAR
  • CHAR
  • DATE
  • TIME
  • TIMESTAMP

Useful Functions & Expressions

  • CAST
  • CASE Expression
  • COALESCE

About db2tutorial.com

The db2tutorial.com website provides you with a comprehensive IBM DB2 tutorial with many practical examples and hands-on sessions.

Recent Tutorials

  • Db2 Functions
  • Db2 RANK
  • Db2 ROW_NUMBER
  • Db2 Window Functions
  • What is Db2

Site Links

  • Home
  • About Us
  • Contact Us
  • Privacy Policy
Copyright © © 2021 by www.db2tutorial.com. All Rights Reserved.