In mysql, data from one table is imported into another table in batches, whether in website development or application development, we often encounter the need to batch import data from a table in MySQL or MS SQLServer to another table, and sometimes even specify the import field. Www.2cto.com this article takes the MySQL database as an example to introduce how to import all data of a table or data of specified fields to the target table through SQL command lines. This method also applies to SQLServer databases, that is, T-SQL. Category 1: If the fields of the two tables (the export table and the target table) are the same and you want to insert all the data, you can use this method: (this method is only suitable for exporting the two tables in the same database) insert into target table SELECT * FROM source table. For example, to INSERT the articles table INTO the newArticles table, you can use the following SQL statement: INSERT INTO newArticles SELECT * FROM articles; type 2: If you only want to import specified fields, you can use this method: www.2cto.com insert into target table (Field 1, Field 2 ,...) SELECT Field 1, Field 2 ,... FROM source table; note that the fields in the above two tables must be consistent (field type); otherwise, a Data Conversion error occurs. 1. insert into openrowset ('sqlodb', 'localhost'; 'sa '; '123', Test. dbo. table_ B) select * from Test. dbo. table_A // enable Ad Hoc Distributed Queries: exec sp_configure 'show advanced options', 1 reconfigureexec sp_configure 'ad Hoc Distributed Queries ', 1 reconfigure www.2cto.com // after use, disable Ad Hoc Distributed Queries: exec sp_configure 'ad Hoc Distributed Queries ', 0 reconfigureexec sp_configure 'show advanced options', 0 reconfigure
2. // The server insert into dbo. table_ B) select * from dbo. table_A Concatenates the table name and database connection string with code and then executes the SQL statement program function you need to complete