Creating a table as an existing table

we can create a table from an exiting table with all / specific columns by following query,

Example 1:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
create table dummy like products.
create table dummy like products.
create table dummy like  products.

will create a table dummy as the structure of products table by copying all the rows .

Example 2:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
create table dummy select * from products
create table dummy select * from products
create table dummy select * from products

will create a table dummy as the structure of products table by copying the rows.

Example 3:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
create table dummy select productid , description, prize
create table dummy select productid , description, prize
create table dummy select productid , description, prize

will create a table dummy with all rows , and the specified columns of pro

Example 4:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
create table dummy select * from products limit 0
create table dummy select * from products limit 0
create table dummy select * from products limit 0

will create a table dummy with all the columns and no rows will be copied.

Inserting rows into a table from another table

Suppose we want to copy all / some of the rows from an existing table with other, apply the following query,

Example 1:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Insert into products select * from products
Insert into products select * from products
Insert into products select * from products

will copies all the rows from the products table into products table.