Create an table from an existing table

Create a table from another table with data, without data, filtered data, and specific columns.

Example: 

From Table: Employee                  To Table : TmpEmployee
ID  FNAME       LNAME               ID   FNAME       LNAME
1   Narottam    Singh               1    Narottam    Singh
2   Ram         Singh               2    Ram         Singh


Mysql:

  • Create a new table from the existing table without data

CREATE TABLE TmpEmployee as 
SELECT * FROM Employee where 1=2;
  • Create a new custom column table from the existing table without data

CREATE TABLE TmpEmployee as 
SELECT FNAME FROM Employee where 1=2;

  • Create a new table from the existing table with data

CREATE TABLE TmpEmployee as 
SELECT * FROM Employee;

//OR

CREATE TABLE TmpEmployee as 
SELECT * FROM Employee WHERE 1=1;

  • Create a new custom column table from the existing table with data

CREATE TABLE TmpEmployee as 
SELECT FNAME FROM Employee;

  • Create a new table from the existing table with filtered data

CREATE TABLE TmpEmployee as 
SELECT * FROM Employee where id=1;


Oracle

  • Create a new table from the existing table without data

CREATE TABLE TmpEmployee as 
SELECT * FROM Employee where 1=2;
  • Create a new custom column table from the existing table without data

CREATE TABLE TmpEmployee as 
SELECT FNAME FROM Employee where 1=2;

  • Create a new table from the existing table with data

CREATE TABLE TmpEmployee as 
SELECT * FROM Employee;

//OR

CREATE TABLE TmpEmployee as 
SELECT * FROM Employee WHERE 1=1;

  • Create a new custom column table from the existing table with data

CREATE TABLE TmpEmployee as 
SELECT FNAME FROM Employee;

  • Create a new table from the existing table with filtered data

CREATE TABLE TmpEmployee as 
SELECT * FROM Employee where id=1;

No comments:

Post a Comment