MySQL select into 和 SQL select into

Now there is a table called student, I want to copy the data in this table to a new table called dust, although I can use the following statement to copy, I always feel uncomfortable, I hope you can help me, thank you. answer 01: create table dust select * from student;//When a new table dust is not created before copying answer 02: insert into dust select * from student;//When a new table dust has been created 
 
 
 

Now please use the select..into.. statement to achieve the above stuff, thank you for your support, thank you again!
Netizen replies: This reply was deleted by the moderator at 2008-09-29 06:37:03
Netizen replies: sqlserver can be written in that way, but it doesn't seem to work in MySQL . In addition, the two ways of writing you said should be the most common. Yes, the
netizen replied: create table dust select * from student;
the netizen replied: The above is what I posted, what I want is the select into statement?


Please help heroes, thank you!
Netizen replies: MySQL does not support the Select Into statement to directly back up the table structure and data, some methods can be used instead, and there are other methods to deal with, summarized as follows: Method 1: MYSQL does not support: Select * Into new_table_name from old_table_name; 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 in to MySQL 4. Select the database 5. Execute: Source The path of the backup table such as: Source d:/ok_db.sql and press Enter. 6. Done. 
 
 
 


MySQL Select into outfile is used to export the specified query data to a file as follows:

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


2. Export the data of the specified query condition 2005-06-08 in the table to outfile1.txt in the root directory of the C drive as follows: Select * into outfile 'c://outfile.txt' from test where beginDate='2008-06- 08'; 


mysql> load data local infile "d:/gpsdata.txt" into table positiondata fields terminated by ';' (userid,latitude,longitude,altitude,speed,innerid,reporttime,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 in the front, (col_name_or_user_var,...) in the back. If you use these attributes to write directly after the table name, this is incorrect, you must write them after fields and lines!

Netizen's reply: Quoting the reply of wufongming on the 5th floor:
MySQL does not support the Select Into statement to directly back up the table structure and data. Some methods can be used instead, and there are other methods to deal with. The summary is as follows: Method 1: MYSQL does not support: Select * Into new_table_name from old_table_name; Alternative: 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 okt… 5 The friend of the building explained the above landlord's doubts about the select into statement in mysql. In mysql, the Select Into statement is not supported to directly back up the table structure and data. 
 
 
 
 

I think method 1 is still much more flexible than method 2, because the solution proposed by a friend upstairs here is to create a new table, and the field name and structure of the table are the same as the original table. If a new table has been created, It's just that there is no data in the table, and the field name of the new table is different from the original table but the type is the same, then the second method is not applicable.

So I think the first method is a little better, and there is room for modification, but it is not easy for the 5th floor friend to explain the problem so well!

The owner can choose according to their needs!
Netizen replies: Yes, it is a good choice to use the select into statement to replicate the data of the table under the SQL SERVER database!
Netizen replies: There is a harvest!
Netizen replied: Thank you, my brother admires it!
Netizen's reply: Quoting the reply of wufongming on the 5th floor:
MySQL does not support the Select Into statement to directly back up the table structure and data. Some methods can be used instead, and there are other methods to deal with. The summary is as follows: Method 1: MYSQL does not support: Select * Into new_table_name from old_table_name; Alternative: 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 -u… 
 
 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326363417&siteId=291194637