Comparison between select into in MySQL and select into in SQL

Source: Internet
Author: User

Comparison between select into in MySQL and select into in SQL

Now there is a table named student. I want to copy the data in this table to a new table named dust.
Answer 01:
Create table dust select * from student; // when no new table dust is created before Replication
Answer 02:
Insert into dust select * from student; // when a new table dust has been created

Now we use the select... into... statement to implement the above.

MySQL does not support the Select Into statement to directly back up the table structure and data. Some methods can be used instead, or other methods can be processed. The following is a summary:
Method 1:
MYSQL does not support:
Select * Into new_table_name from old_table_name; usage in SQL server
Alternative method:
Create table new_table_name (Select * from old_table_name );


Method 2:
1. Back up the table structure and data first.
# Export command-u user name-p password-h Host IP Address Database Name table name 1> export file. SQL
Mysqldump-uroot-proot-h192.168.0.88 OK _db oktable2> OK _db. SQL

2. Modify the name of the backup table
3. log on to MySQL
4. Select a database
5. Run the following command: Source backup table path: Source d:/OK _db. SQL, and press Enter.
6. Complete.


MySQL Select into outfile is used to export the specified data to the file:

1.export all data in the table to the cdisk root directory outfile.txt as follows:
Select * into outfile 'C: // outfile.txt 'from test;


2. In the export table, specify the data with the query Condition No. 2005-06-08to the cdisk root directory outfile1.txt as follows:
Select * into outfile 'C: // outfile.txt 'from test where beginDate = '2017-06-08 ';


Mysql> load data local infile "d:/gpsdata.txt" into table positiondata fields terminated by ';' (userid, latitude, longpolling, altitude, speed, innerid, repo
Rttime, status );


Load data [LOW_PRIORITY CONCURRENT] [LOCAL] INFILE 'file_name.txt'
[Replace ignore]
Into table tbl_name
[FIELDS
[Terminated by 'string']
[[OPTIONALLY] enclosed by 'Char ']
[Escaped by 'Char ']
]
[LINES
[Starting by 'string']
[Terminated by 'string']
]
[IGNORE number LINES]
[(Col_name_or_user_var,...)]
[SET col_name = eXPr,...)]

Fields and lines are at the front, (col_name_or_user_var ,...) If you put the attributes you want to write directly after the table name when using it, this is incorrect and must be written after fields and lines!

In addition, table A cannot have an auto-increment ID when copying data to table B.

If auto-increment IDs exist, auto-increment IDs are not inserted.

Insert into B (title) select title from

This article permanently updates the link address:

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.