I have a mysql table with members, about 1400 records, and I am going to switch to a new membership software (amember v3 to amemberv4). The problem is that amember v4 is a whole new program so the database tables cannot have any missing records or it will reorder based on the primary key. For instance, membership ID in a members table which are associated with product IDs in a product table. There is a fact table that references this dimensions.
My problem is how to add in null records with a starting membership ID of those missing. For example the table begins with membership ID 4 instead of 1,2,3. I need help finding a solution to add these missing records based on membership ID’s that are missing. I did make a second table based on the first one (membersold, members) as I am sure I need to join them on each other to create an update statement to add those missing records. There are about 7 columns that will be just null values.
Any ideas?
First of all: what both Jan Dvorak and Michael Berkowski said is absolutely true. Therefore, check carefully that you really need this hack, for chances are overwhelming that you don’t.
But just in case, just for the heck of it, this inserts all IDs into a table – provided they are primary keys, and that they don’t already exist.
Almost any other way is better (except maybe doing it by hand), but requires procedures in either MySQL or other languages.
As I said, this is a very ugly way to do things.
If you have any language available at all, you can generate the insert queries and run them, e.g. in bash:
or in PHP, python, or Perl — you just generate a SQL INSERT statement of the form
and fill in the blanks with an incrementing counter, then send the statement to the database. The
IGNOREwill skip the values that are already there. How you fill the blanks depends on the language you choose. If you need to populate other fields, enter the names afteridand their default values after the blanks.