Create New Table by Selecting Data from Other Tables with CREATE TABLE AS
By using SQL data manipulation statement, a new, temporary, backup or regular table can be created and filled or inserted with data from another table or tables retrieved by SELECT statement. The SQL data manipulation language is CREATE TABLE AS which can be used to create a new table built from contents of result set by a query on a table that already exists within the database. Both the column types, and row data for the new table, come from the SELECT command specified by select.
CREATE TABLE AS has the following syntax or synopsis in simple form:
CREATE TABLE new_table_name [ ( column [, ...] ) ] AS SELECT [ ( column [, ...] ) ] FROM existing table_name
The SELECT statement can be in a complex form where data is been retrieved from several tables. For the new table, column names can be specified by including the column names in a comma-delimited list. Very important point to take note is that there should be the same number of columns specified in the column list preceding the AS clause (optional, if specified) for new table as the number of target columns that are returned by the select statement. If the optional list of columns in parentheses of new table contains different number of rows than the rows the SELECT statement returns, the following error message will be displayed:
ERROR: CREATE TABLE/AS SELECT has mismatched column count
In its simplest form, CREATE TABLE AS statement will create a complete backup of an existing table including all columns and data simply by using the statement CREATE TABLE new_table_name AS SELECT * FROM existing_table_name.
Share and contribute or get technical support and help at My Digital Life Forums.
Related Articles
- Easily Duplicate, Copy or Backup Tables in Oracle, PostgreSQL, DB2 and SQLite with Create Table As SQL
- ORA-00942 Table or View Does Not Exist Oracle Error
- ORA-02449 Oracle Drop Table Error
- Oracle ORA-14074 Create or Add New Partition Fails Error
- Create, Add or Split Oracle Database Partition Fails with ORA-14080 Error
- Check and Optimize MySQL Database Automatically with Crontab/Cron
- How to Backup and Restore (Export and Import) MySQL Databases Tutorial
- SLIC Table (SLIC.BIN or ACPISLIC.BIN) BIOS File for OEMs Download
- Oracle EXP-00091 Error When Export Database
- Sun Table Transforms Solar Energy to Electricity to Power Up Home Appliances

































April 1st, 2007 03:26
We can do it also with the query,
SELECT * INTO newtable FROM existingtable
I think its a little bit shorter.
January 10th, 2008 13:31
Data in the table that is created using create table as select” is different from the data that is returned when the same select that creates the table is executed separately????
WE are using the tool PL/SQL Developer .
Any idea what this problem is due to?