Creating a Table in IBM Db2 | Generated by AI

Home PDF

Creating a table in IBM Db2 involves using SQL statements. Below are the steps and examples for creating a table and creating a table based on another table in a different schema.

Creating a Table in IBM Db2

To create a table in IBM Db2, you use the CREATE TABLE statement. Here’s an example:

CREATE TABLE my_schema.my_table (
    column1 INTEGER PRIMARY KEY,
    column2 VARCHAR(50),
    column3 DATE
);

In this example:

Creating a Table Based on Another Table in Another Schema

To create a table based on another table in a different schema, you can use the CREATE TABLE AS statement. This allows you to create a new table with the same structure and data as an existing table. Here’s an example:

CREATE TABLE my_schema.new_table AS (
    SELECT * FROM another_schema.existing_table
) WITH NO DATA;

In this example:

Additional Considerations

Would you like more detailed examples or explanations on any specific part of this process?


Back 2025.04.09 Donate