0

I have an SQL script that creates three new tables in a MySQL database, installs fields in those new tables.

Several of the tables in this database contain meta-data on the tables that contain user data, and my script adds records to these meta-data tables, to make the new tables and fields visible to the application. For example, for table "foo," a record has to be added to the "objects" table, and for each field in "foo," a record has to be added to the "fields" table, telling the application what it needs to know about the field. If "foo" is given an ID of 51 in the "objects" table, then all of the records for "foo" fields in the "fields" table have to list it as being in object 51.

(This is actually a simplified version; the real thing is more complicated.)

At present, my script overrides the auto-increment on the ID fields for "objects" and "fields," and uses hard-coded IDs on the INSERT statements for those records, putting them into a range that's unlikely to collide with any existing records.

But if we need to use a different range, then we need to do a search-and-replace on all of those hard-coded IDs.

Is there a way I could replace the hard-coded IDs with something that would allow us to easily put the range anywhere it needs to go?

1 Answers1

1

I think that could help you

How to declare a variable in MySQL?

"There are mainly three types of variables in MySQL:

  1. User-defined variables (prefixed with @)
  2. Local Variables (no prefix)
  3. Server System Variables (prefixed with @@)"