更新数据库中的现有值

时间:2013-12-29 03:51:23

标签: mysql database

我创建了一个数据库表,其中包含5列uniqueID(自动增量),名称,大学,移动,事件(12事件复选框)。所以我的问题是每次用户注册唯一的id增量并且我想要另一个事件到已经存在的uniqueId时,有没有可能的方法来添加/更新它而不必全部到数据库并在那里编辑它?

1 个答案:

答案 0 :(得分:0)

好的,在评论之后,我建议您执行以下操作。

你需要两张桌子。

user
 - userid (unique, auto-increment)
 - name
 - college
 - mobile

event
 - eventid (unique, auto-increment)
 - userid (not-unique, connects to the user)

当用户注册时,您可以创建user记录和第一个event记录。然后,当用户添加另一个事件时,您将添加另一个event记录。

更新:

我试图慢慢地教你,但是peterm在他的评论中是正确的。最好的方法实际上就是这样:

user
 - userid (unique)
 - fields relevant only to the user

event
 - eventid (unique)
 - fields relevant to the event (e.g., date, place etc)

user_event
 - userid
 - eventid  (where you have a unique key that includes two fields, userid and eventid)

您也可能还有一个college记录......

但正如我所说,我只是想让你朝着正确的方向前进。