I have two tables:
create table `db_csms`.`tbl_item_requester`
(
`id` int not null,
`item_id` int not null,
`requester_id` int not null,
foreign key(`item_id`) references `db_csms`.`tbl_items`(`item_id`),
foreign key(`requester_id`) references `db_csms`.`tbl_user_details`(`user_id`),
primary key (`id`)
);
create table `db_csms`.`tbl_item_requests`
(
`id` int not null,
`item_requester_id` int not null,
`quantity` int(5) not null default 0,
foreign key(`item_requester_id`) references `db_csms`.`tbl_item_requester`(`id`),
primary key (`id`)
);
tbl_items and tbl_user_details are already populated with values. My problem is when a new row is added into table 1 because the table 2 uses the id of that new row inserted in table 1.
My issues are:
- How to get the newly inserted row id of
table 1which is needed for inserting intable 2.
Strategy to solve this issue(my thinking):
- Remove auto_increment and then generate a random value (using C# code) and use that value in both tables.
Are there any workaround to this problem? Do i have to change my strategy? Is the Database design incorrect?
last_insert_id(): dev.mysql.com/doc/refman/5.7/en/….MySqlCommand