SQL statements that are completely replicated between MySQL SQL two sheets

Source: Internet
Author: User
Tags mysql tutorial reserved

In MySql4.0.12, with the "CREATE TABLE Bak_name as SELECT * from Original_name" statement

, the generated Bak table does not have a primary key and the index, the use of the time to pay attention to. You can build a table structure that you want to back up first

Sample table Back_name, pour the data in the following ways

INSERT INTO bak_table SELECT * Original_name This method


In the MySQL tutorial, you can copy a table that already exists directly from a command to another table

Methods 1:create Table MMM select * from BBB; Note: This command requires MMM this table in the database tutorial

does not exist
This command creates a new table mmm and the table structure in BBB and the data and MMM are exactly the same, and you can export some fields

Create Table mmm Select field 1, Field 2 from BBB;

Methods 2:insert into MMM select * BBB; This statement implements the same function as the previous statement, and only requires

The MMM table must exist in the database

Mysql>
mysql> CREATE TABLE Topic (
   ->    topicid      SMALLINT not NULL auto_increment PRIMARY KEY,
   ->    name & nbsp;      VARCHAR not NULL,
   ->    instock      SMALLINT UNSIGNED not NULL,
   ->    onorder      SMALLINT UNSIGNED not NULL,
   ->    reserved     SMALLINT UNSIGNED not NULL,
   ->    department  ENUM (' Classical ', ' Popular ') not NULL,
   ->    category    VARCHAR is not NULL,
   ->    rowupdate   TIMESTAMP not NULL
   ->) ;
Query OK, 0 rows affected (0.03 sec)

Mysql>
Mysql>
Mysql> INSERT into Topic (Name, Instock, Onorder, Reserved, Department,

Category) VALUES
-> (' Java ', 5, 3, ' popular ',

' Rock '),
-> (' JavaScript ', 10, 5, 3,

' Classical ', ' Opera ',
-> (' C Sharp ', 4, 1, ' popular ',

' Jazz '),
-> (' C ', 9, 4, 2,

' Classical ', ' dance '),
-> (' C + + ', 24, 2, 5,

' Classical ', ' General ',
-> (' Perl ', 16, 6, 8,

' Classical ', ' vocal '),
-> (' Python ', 2, 6, ' popular ',

' Blues '),
-> (' Php ', 3, ten, ' Popular ',

' Jazz '),
-> (' asp.net ', A, A, ' popular ',

' Country '),
-> (' vb.net ', 5, ten, ' Popular ',

' New age '),
-> (' vc.net ', all, one, one, ' popular ',

' New age '),
-> (' UML ', 42, 17, 17,

' Classical ', ' General ',
-> (' www.java2s.com ', 25, 44, 28,

' Classical ', ' dance '),
-> (' Oracle ', 32, 15, 12,

' Classical ', ' General ',
-> (' Pl/sql ', 20, 10, 5,

' Classical ', ' Opera ',
-> (' SQL Server ', 23, 12, 8,

' Classical ', ' general ');
Query OK, Rows Affected (0.00 sec)
Records:16 duplicates:0 warnings:0

Mysql>
Mysql> select * from Topic;
+---------+----------------+---------+---------+----------+------------+--------

--+---------------------+
| TopicID | Name | Instock | Onorder | Reserved | Department | Category

| Rowupdate |
+---------+----------------+---------+---------+----------+------------+--------

--+---------------------+
| 1 |      Java |       10 |        5 | 3 | Popular | Rock

| 2007-07-23 19:09:52 |
| 2 |      JavaScript |       10 |        5 | 3 | Classical | Opera

| 2007-07-23 19:09:52 |
| 3 |      C Sharp |       17 |        4 | 1 | Popular | Jazz

| 2007-07-23 19:09:52 |
| 4 |       C |       9 |        4 | 2 | Classical | Dance

| 2007-07-23 19:09:52 |
| 5 |      C + + |       24 |        2 | 5 | Classical | General

| 2007-07-23 19:09:52 |
| 6 |      Perl |       16 |        6 | 8 | Classical | Vocal

| 2007-07-23 19:09:52 |
| 7 |       Python |      2 |        25 | 6 | Popular | Blues

| 2007-07-23 19:09:52 |
| 8 |      PHP |       32 |       3 | 10 | Popular | Jazz

| 2007-07-23 19:09:52 |
| 9 |      asp.net |      12 |       15 | 13 | Popular | Country

| 2007-07-23 19:09:52 |
| 10 |       vb.net |      5 |       20 | 10 | Popular | New Age

| 2007-07-23 19:09:52 |
| 11 |      vc.net |      24 |       11 | 14 | Popular | New Age

| 2007-07-23 19:09:52 |
| 12 |      UML |      42 |       17 | 17 | Classical | General

| 2007-07-23 19:09:52 |
| 13 |      www.java2s.com |      25 |       44 | 28 | Classical | Dance

| 2007-07-23 19:09:52 |
| 14 |      Oracle |      32 |       15 | 12 | Classical | General

| 2007-07-23 19:09:52 |
| 15 |      Pl/sql |      20 |        10 | 5 | Classical | Opera

| 2007-07-23 19:09:52 |
| 16 |      SQL Server |      23 |        12 | 8 | Classical | General

| 2007-07-23 19:09:52 |
+---------+----------------+---------+---------+----------+------------+--------

--+---------------------+
Rows in Set (0.00 sec)

Mysql>
mysql> CREATE TABLE Topic2
   -> (
   ->  & nbsp TopicID SMALLINT NOT null PRIMARY KEY,
   ->    Name VARCHAR (x) not NULL,
&NBSP ;  ->    instock SMALLINT UNSIGNED not NULL
   ->)
    -> SELECT TopicID, Name, Instock
   -> from Topic
   -> WHERE Cate Gory= ' Blues ' or category= ' Jazz ';
Query OK, 3 rows affected (0.01 sec)
records:3  duplicates:0  warnings:0

Mysql>
Mysql> select * from Topic2;
+---------+---------+---------+
| TopicID | name    | Instock |
+---------+---------+---------+
|       3 | C Sharp |      17 |
|       7 | python  |       2 |
|       8 | php     |      32 |
+---------+---------+---------+
3 rows in Set (0.00 sec)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.