DB2 Tutorial

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

Db2 RENAME TABLE

Summary: in this tutorial, you will learn how to use the Db2 RENAME TABLE statement to change the name of a table to the new one.

Introduction to Db2 RENAME TABLE statement

To change the name of an existing table to a new one, you use the RENAME TABLE statement.

Here is the syntax of the RENAME TABLE statement:

RENAME TABLE table_name TO new_table_name;

In this syntax:

  • First, specify the name of the table to which you want to rename after the RENAME TABLE keywords.
  • Then, specify the new name of the table after the TO keyword.

Db2 requires that the table, which you want to rename, must meet the following requirements:

  • The table must not have any reference in existing objects such as view, triggers, functions, or constraints.
  • The table must not have any generated column, other than the identity column, or be a parent or dependent table.

Notice that this behavior is different from other database systems such as Oracle and SQL Server, which mark the dependent objects of the table invalid.

Db2 RENAME TABLE statement example

First, create a new table named favorites:

CREATE TABLE favorites ( book_id INT NOT NULL, user_id INT NOT NULL, PRIMARY KEY (book_id,user_id) );

Then, use the RENAME TABLE statement to change the favorites table to favorite_books table:

RENAME TABLE favorites TO favorite_books;

In this tutorial, you have learned how to use the DB2 RENAME TABLE statement to change the name of a table to the new one.

  • Was this tutorial helpful ?
  • YesNo
Previous Db2 TRUNCATE TABLE
Next Db2 Integers

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.