Creating Copies of a Table : Create Table « Table Index « SQL / MySQL

Home
SQL / MySQL
1.Aggregate Functions
2.Backup Load
3.Command MySQL
4.Cursor
5.Data Type
6.Database
7.Date Time
8.Engine
9.Event
10.Flow Control
11.FullText Search
12.Function
13.Geometric
14.I18N
15.Insert Delete Update
16.Join
17.Key
18.Math
19.Procedure Function
20.Regular Expression
21.Select Clause
22.String
23.Table Index
24.Transaction
25.Trigger
26.User Permission
27.View
28.Where Clause
29.XML
SQL / MySQL » Table Index » Create Table 
Creating Copies of a Table
        
mysql>
mysql>
mysql> CREATE TABLE employee (
    ->     id int unsigned not null auto_increment primary key,
    ->     firstname varchar(20),
    ->     lastname varchar(20),
    ->     title varchar(30),
    ->     age int,
    ->     yearofservice int,
    ->     salary int,
    ->     perks int,
    ->     email varchar(60)
    -> );
Query OK, rows affected (0.00 sec)

mysql>
mysql> INSERT INTO employee (firstname, lastName, title, age, yearofservice, salary, perks, emailvalues ("John""Chen
""Senior Programmer"31312000025000"[email protected]");
Query OK, row affected (0.00 sec)

mysql> INSERT INTO employee (firstname, lastName, title, age, yearofservice, salary, perks, emailvalues ("Jan""Pilla
i""Senior Programmer"32411000020000"[email protected]");
Query OK, row affected (0.00 sec)

mysql> INSERT INTO employee (firstname, lastName, title, age, yearofservice, salary, perks, emailvalues ("Ane""Pandi
t""Web Designer"2439000015000"[email protected]");
Query OK, row affected (0.00 sec)

mysql> INSERT INTO employee (firstname, lastName, title, age, yearofservice, salary, perks, emailvalues ("Mary""Anch
or""Web Designer"2728500015000"[email protected]");
Query OK, row affected (0.00 sec)

mysql> INSERT INTO employee (firstname, lastName, title, age, yearofservice, salary, perks, emailvalues ("Fred""King
""Programmer"3237500015000"[email protected]");
Query OK, row affected (0.00 sec)

mysql> INSERT INTO employee (firstname, lastName, title, age, yearofservice, salary, perks, emailvalues ("John""Mac"
"Programmer"3248000016000"[email protected]");
Query OK, row affected (0.00 sec)

mysql> INSERT INTO employee (firstname, lastName, title, age, yearofservice, salary, perks, emailvalues ("Arthur""Sa
m""Programmer"2827500014000"[email protected]");
Query OK, row affected (0.00 sec)

mysql> INSERT INTO employee (firstname, lastName, title, age, yearofservice, salary, perks, emailvalues ("Alok""Nand
a""Programmer"3237000010000"[email protected]");
Query OK, row affected (0.00 sec)

mysql> INSERT INTO employee (firstname, lastName, title, age, yearofservice, salary, perks, emailvalues ("Susan""Ra"
"Multimedia Programmer"3249000015000"[email protected]");
Query OK, row affected (0.00 sec)

mysql> INSERT INTO employee (firstname, lastName, title, age, yearofservice, salary, perks, emailvalues ("Paul""Simo
n""Multimedia Programmer"2318500012000"[email protected]");
Query OK, row affected (0.00 sec)

mysql> INSERT INTO employee (firstname, lastName, title, age, yearofservice, salary, perks, emailvalues ("Edward""Pa
rhar""Multimedia Programmer"3027500015000"[email protected]");
Query OK, row affected (0.00 sec)

mysql> INSERT INTO employee (firstname, lastName, title, age, yearofservice, salary, perks, emailvalues ("Kim""Hunte
r""Senior Web Designer"32411000020000"[email protected]");
Query OK, row affected (0.00 sec)

mysql> INSERT INTO employee (firstname, lastName, title, age, yearofservice, salary, perks, emailvalues ("Roger""Lew
is""System Administrator"32310000013000"[email protected]");
Query OK, row affected (0.00 sec)

mysql> INSERT INTO employee (firstname, lastName, title, age, yearofservice, salary, perks, emailvalues ("Danny""Gib
son""System Administrator"3129000012000"[email protected]");
Query OK, row affected (0.00 sec)

mysql> INSERT INTO employee (firstname, lastName, title, age, yearofservice, salary, perks, emailvalues ("Mike""Harp
er""Senior Marketing Executive"36112000028000"[email protected]");
Query OK, row affected (0.00 sec)

mysql> INSERT INTO employee (firstname, lastName, title, age, yearofservice, salary, perks, emailvalues ("Mary""Sund
ay""Marketing Executive"3159000025000"[email protected]");
Query OK, row affected (0.00 sec)

mysql> INSERT INTO employee (firstname, lastName, title, age, yearofservice, salary, perks, emailvalues ("Jack""Sim"
"Marketing Executive"2717000018000"[email protected]");
Query OK, row affected (0.00 sec)

mysql> INSERT INTO employee (firstname, lastName, title, age, yearofservice, salary, perks, emailvalues ("Joe""Irvin
e""Marketing Executive"2717200018000"[email protected]");
Query OK, row affected (0.00 sec)

mysql> INSERT INTO employee (firstname, lastName, title, age, yearofservice, salary, perks, emailvalues ("Henry""Ali
""Customer Service Manager"323700009000"[email protected]");
Query OK, row affected (0.00 sec)

mysql> INSERT INTO employee (firstname, lastName, title, age, yearofservice, salary, perks, emailvalues ("Peter""Cha
mpion""Finance Manager"32212000025000"[email protected]");
Query OK, row affected (0.00 sec)

mysql>
mysql> select from employee;
+----+-----------+----------+----------------------------+------+---------------+--------+-------+---------------------+

| id | firstname | lastname | title                      | age  | yearofservice | salary | perks | email               |

+----+-----------+----------+----------------------------+------+---------------+--------+-------+---------------------+

|  | John      | Chen     | Senior Programmer          |   31 |             120000 25000 [email protected]       |

|  | Jan       | Pillai   | Senior Programmer          |   32 |             110000 20000 [email protected]         |

|  | Ane       | Pandit   | Web Designer               |   24 |             |  90000 15000 [email protected]         |

|  | Mary      | Anchor   | Web Designer               |   27 |             |  85000 15000 [email protected]          |

|  | Fred      | King     | Programmer                 |   32 |             |  75000 15000 [email protected]           |

|  | John      | Mac      | Programmer                 |   32 |             |  80000 16000 [email protected]       |

|  | Arthur    | Sam      | Programmer                 |   28 |             |  75000 14000 [email protected]         |

|  | Alok      | Nanda    | Programmer                 |   32 |             |  70000 10000 [email protected]         |

|  | Susan     | Ra       | Multimedia Programmer      |   32 |             |  90000 15000 [email protected]         |

10 | Paul      | Simon    | Multimedia Programmer      |   23 |             |  85000 12000 [email protected]        |

11 | Edward    | Parhar   | Multimedia Programmer      |   30 |             |  75000 15000 [email protected]       |

12 | Kim       | Hunter   | Senior Web Designer        |   32 |             110000 20000 [email protected]    |

13 | Roger     | Lewis    | System Administrator       |   32 |             100000 13000 [email protected]      |

14 | Danny     | Gibson   | System Administrator       |   31 |             |  90000 12000 [email protected]   |

15 | Mike      | Harper   | Senior Marketing Executive |   36 |             120000 28000 [email protected]         |

16 | Mary      | Sunday   | Marketing Executive        |   31 |             |  90000 25000 [email protected]  |

17 | Jack      | Sim      | Marketing Executive        |   27 |             |  70000 18000 [email protected]       |

18 | Joe       | Irvine   | Marketing Executive        |   27 |             |  72000 18000 [email protected]  |

19 | Henry     | Ali      | Customer Service Manager   |   32 |             |  70000 |  9000 [email protected] |

20 | Peter     | Champion | Finance Manager            |   32 |             120000 25000 [email protected]     |

+----+-----------+----------+----------------------------+------+---------------+--------+-------+---------------------+

20 rows in set (0.00 sec)

mysql>
mysql>
mysql> CREATE TABLE newtable SELECT FROM employee;
Query OK, 20 rows affected (0.01 sec)
Records: 20  Duplicates: 0  Warnings: 0

mysql>
mysql> select from newtable;
+----+-----------+----------+----------------------------+------+---------------+--------+-------+---------------------+

| id | firstname | lastname | title                      | age  | yearofservice | salary | perks | email               |

+----+-----------+----------+----------------------------+------+---------------+--------+-------+---------------------+

|  | John      | Chen     | Senior Programmer          |   31 |             120000 25000 [email protected]       |

|  | Jan       | Pillai   | Senior Programmer          |   32 |             110000 20000 [email protected]         |

|  | Ane       | Pandit   | Web Designer               |   24 |             |  90000 15000 [email protected]         |

|  | Mary      | Anchor   | Web Designer               |   27 |             |  85000 15000 [email protected]          |

|  | Fred      | King     | Programmer                 |   32 |             |  75000 15000 [email protected]           |

|  | John      | Mac      | Programmer                 |   32 |             |  80000 16000 [email protected]       |

|  | Arthur    | Sam      | Programmer                 |   28 |             |  75000 14000 [email protected]         |

|  | Alok      | Nanda    | Programmer                 |   32 |             |  70000 10000 [email protected]         |

|  | Susan     | Ra       | Multimedia Programmer      |   32 |             |  90000 15000 [email protected]         |

10 | Paul      | Simon    | Multimedia Programmer      |   23 |             |  85000 12000 [email protected]        |

11 | Edward    | Parhar   | Multimedia Programmer      |   30 |             |  75000 15000 [email protected]       |

12 | Kim       | Hunter   | Senior Web Designer        |   32 |             110000 20000 [email protected]    |

13 | Roger     | Lewis    | System Administrator       |   32 |             100000 13000 [email protected]      |

14 | Danny     | Gibson   | System Administrator       |   31 |             |  90000 12000 [email protected]   |

15 | Mike      | Harper   | Senior Marketing Executive |   36 |             120000 28000 [email protected]         |

16 | Mary      | Sunday   | Marketing Executive        |   31 |             |  90000 25000 [email protected]  |

17 | Jack      | Sim      | Marketing Executive        |   27 |             |  70000 18000 [email protected]       |

18 | Joe       | Irvine   | Marketing Executive        |   27 |             |  72000 18000 [email protected]  |

19 | Henry     | Ali      | Customer Service Manager   |   32 |             |  70000 |  9000 [email protected] |

20 | Peter     | Champion | Finance Manager            |   32 |             120000 25000 [email protected]     |

+----+-----------+----------+----------------------------+------+---------------+--------+-------+---------------------+

20 rows in set (0.00 sec)

mysql>
mysql>
mysql> drop table employee;
Query OK, rows affected (0.00 sec)

mysql> drop table newtable;
Query OK, rows affected (0.00 sec)

mysql>

   
    
    
    
    
    
    
    
  
Related examples in the same category
1.Create Simple Tables
2.Create table: default value for column
3.Create table: small int and unsigned int
4.Create table: smallint, decimal and float
5.Create table: char, varchar
6.Create table: BLOB
7.Create table: char set and language
8.Create table: ENUM and set
9.Create table: YEAR and TIMESTAMP
10.Create table: null and not null
11.Create table: not null and default value
12.Create table: default int value
13.Create table: primary key
14.Create table: primary key 2
15.Create table: two columns for primary key
16.Create table: auto increment primary key
17.Create table: REFERENCES
18.Create table: foreign key
19.Create table: engine type INNODB
20.Set average row length and max, min rows
21.Syntax for Creating Tables (CREATE TABLE)
22.Create an empty table, use a WHERE clause that is always false
23.To produce a summary that includes all hours of the day, create a reference table that lists each hour
24.Creates table-level privileges.
25.Create a copy of the product table:
26.Create a table called cust_names using the table definitions and data from the product table.
27.CREATE TABLE IF NOT EXISTS
28.CREATE TABLE TEAMS_COPY1 LIKE TEAMS
29.Creating a New Table by Copying
30.Creating a Table
31.Add an IF NOT EXISTS clause to the statement:
java2s.com  |  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.