Avatar of MRDELPHI
MRDELPHI

asked on 

Copy data

Hi All :
I've Delphi application, I would like to copy Data from one mysql table to another mysql table with the same structure. for loop its seems too slow. is there any query to do that

thanks
DelphiMySQL ServerSQL

Avatar of undefined
Last Comment
systan
Avatar of johanntagle
johanntagle
Flag of Philippines image

insert into table2 select * from table1;

I suggest you still do it in batches.  For example if you have a numeric primary key:

insert into table2 select * from table1 where primary_key_column between 1 and 5000;

Then just have Delphi call that statement, changing 1 and 5000 to the next batch, and so on.
Avatar of MRDELPHI
MRDELPHI

ASKER

I am trying to do that but there is an error occurred

User generated image
when i write the "select a.code, a.qty from master a where a.sn between 2610 and 2630"
its return the correct result. but in the insert statement there is an error
ASKER CERTIFIED SOLUTION
Avatar of johanntagle
johanntagle
Flag of Philippines image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of systan
systan
Flag of Philippines image

//use Create Like:
command := 'CREATE TABLE items2 LIKE items1';
...
...
//then insert
command := 'INSERT INTO items2 SELECT * FROM items1';
...
SQL
SQL

SQL (Structured Query Language) is designed to be used in conjunction with relational database products as of a means of working with sets of data. SQL consists of data definition, data manipulation, and procedural elements. Its scope includes data insert, query, update and delete, schema creation and modification, and data access control.

61K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo