MySQL Autoincrement on Same variable for Two Tables

78 views Asked by At

Let's say I have these two very tables

CREATE TABLE Orders(orderid int, customerid int, itemid int, order_name varchar(30));

CREATE TABLE Order2(orderid int, customerid int, itemid int, order_name varchar(30));

However, I don't want either of these two tables to have the same orderid, but I want them to autoincrement together. For example if the last insertion made the current Order2.orderid equal to 5, then the next orderid in Order will be equal to 6. The next orderid in Order2 could still be equal 6 if it is not inserted in Order. But they CANNOT BOTH contain an orderid of 6. The rest of the columns do not necessarily have a relationship.

I was wondering if it is possible to do something like this in MySQL? Without changing the structure/relationship of MySQL. These are not my actual tables in my database, this example was just to illustrate what I am trying to do.

I'm trying to avoid changing the structure or relationship of my table.

0

There are 0 answers