开发者

Database auto increment primary key with business login

开发者 https://www.devze.com 2023-04-07 07:18 出处:网络
I have a database with USERS table and EVENTS table, both with auto increment integer primary key called id. when the client app start an event, a message sent to开发者_开发知识库 the server, and the

I have a database with USERS table and EVENTS table, both with auto increment integer primary key called id. when the client app start an event, a message sent to开发者_开发知识库 the server, and the server creates a new EVENT entry in the EVENTS table with the username of the user that started the event(and some more data). now what is the best practice to refetch this event when needed? for example if the next day the user wants to ask the server for this event should the server search the EVENT table by username(every user have only one event in the table)? If so isn't less efficient to search by string then by the event integer id? or maybe when the server creates the event entry in the EVENTS table i need to send the user the entry id, so the next time the user ask for the event he can ask it with the id? but if i do it this way im using the auto increment id with the business login and im not sure this is good..


You want to use a foreign key. in events with the user id

To get the events done by a particular user, you just do

select events.*, users.* from users left join events where users.id = events.user_id
WHERE user.username = 'johnboy'
0

精彩评论

暂无评论...
验证码 换一张
取 消