Friday, 15 January 2010

mysql - How to add data if the primary key is used as foreign key in the same table? -



mysql - How to add data if the primary key is used as foreign key in the same table? -

i implementing referral scheme in user can come form reference of registered user of scheme or can register manually without reference. problem facing if user not using reference token register referee of user user itself. how can save info (foreign key) of user before getting primary key of row (that comes auto increment method)? more clearance attaching image.

thanks in advance.

one way go auto generate key before inserting instead of using auto increment feature. easiest way of doing define id columns uuids instead of ints , generate next id application.

a better, though, imho, alter design, , instead of using user own referral in case wasn't referred user explicitly state has no referral , utilize null value there.

mysql database erd

No comments:

Post a Comment