Home >Database >Mysql Tutorial >How to Create a Table Structure in Oracle Without Copying Data?

How to Create a Table Structure in Oracle Without Copying Data?

DDD
DDDOriginal
2025-01-01 12:16:17739browse

How to Create a Table Structure in Oracle Without Copying Data?

Creating a Table Structure Without Copying Data in Oracle

When duplicating an Oracle table, it's common to use the statement "create table xyz_new as select * from xyz;" to copy both the structure and data. However, if you only require the structure without data, there's a simple solution.

Solution:

To create a copy of a table's structure without its data, use the following statement:

create table xyz_new as select * from xyz where 1=0;

By adding the "where 1=0" clause, you ensure that no rows are selected from the original table, effectively copying only its structure.

Limitations:

It's important to note that this method has some limitations:

  • Sequences, triggers, indexes, and certain constraints may not be copied over.
  • Materialized view logs are not handled.
  • Partitions are also not handled in this approach.

Therefore, if you require these elements to be included in the new table, you may need to employ alternative methods or consider creating the table manually with the desired settings.

The above is the detailed content of How to Create a Table Structure in Oracle Without Copying Data?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn