distal-attribute
distal-attribute
distal-attribute
distal-attribute

Looping in HeidiSQL

tomthirteen posted 1 month ago in General

Hello all,

Hope this isn't a silly question. I have 269 databases of Wikipedias by language. One table in each has fields of titles and of country of origin of edits done to those page title. I would like to loop through the table and copy the row by country of origin and place them into a database according to country. I could easily imagine how to do this using Python, but I'm having difficulty in HeidiSQL. My pseudo-code would be something like this:

-- Loop through country field, set variable country -- if table in database doesn't exist, create it -- if table in database exists, update it -- copy record to appropriate database/table according to country -- end loop

I can't even declare a user set variable. Could someone give me a heads up on how to do this? Is there good documentation for these functions somewhere?

Your help is much appreciated, Tom

endo64 posted 4 weeks ago

I don't think you can do that in HeidiSQL directly without using a scripting language (I don't know if HeidiSQL supports any) as you need to connect different databases each time.

You can do lOOPs and IFs in SQL for sure, but you cannot connect another database conditionally.

If you are on MSSQL, then generate your SQL conditionally and use 3-4 parts notation (https://www.mssqltips.com/sqlservertip/1095/sql-server-four-part-naming/) to specify the other databases.

But it is much easier with Python or any other scripting language.

Please login to leave a reply, or register at first.