Reputation: 4962
Is that possible making sure same ID wont appear twice in 2 tables?
For example i've got this colum: call id
and I want to make sure it'll count it in both tables
for ex: calls_to_x
and calls_to_y
I want to enter both tables data and to make sure the call id
colum will increase from both table for ex:
calls_to_x
:
Call id: 1 parameters: .... time: 01:00:00
Call id: 3 parameters: .... time: 01:30:00
calls_to_y
:
Call id: 2 parameters: .... time: 01:10:00
Call id: 4 parameters: .... time: 01:34:00
Upvotes: 0
Views: 198
Reputation: 418
Another option would be to have a table that is AllCalls that has a callid and at recipient then include this id as a foreign key in either of the two tables. Only the fields that are different could be in the calls_to_x and calls_to_y table things that are generally applicable to any call could all be in the AllCalls table.
Upvotes: 1
Reputation: 52802
The answer depends on what RDBMS you're using.
For MySQL:
If you only need unique values (and not sequential), you can use something like an UUID to uniquely identify each row.
If you do need the values to be sequential, either merge the tables to one single table by having a field indicating the type of content or use a third table to keep track of used ids with an id field and auto_increment for that column. A second column can keep track of which table used the id if needed. You can INSERT INTO that table in an SQL function and return the value of LAST_INSERT_ID() to get the next id for your other tables.
For most other RDBMSes
Use a sequence (CREATE SEQUENCE).
Upvotes: 1