开发者

MySQL: Table entry representing all 'ids'?

I have a single value in a table that I want selected every time a query is made on the table.

Let me break is down.

I have the following entry:

MySQL: Table entry representing all 'ids'?

Instead of making a new entry for every different user_id, can I use some kind is primitive to represent ALL 开发者_C百科user_ids instead of specific ids? Example below:

MySQL: Table entry representing all 'ids'?

For reasons that I would rather not take the time to explain, this is what I need. Is there any way to do this?

Thanks in advance!


If I'm correct in assuming that that means you want tag_id linked to every user_id (as some sort of a catch-all clause), you have a few ways of going about it. Depending on your application, you can simply request it to add a row for tag_id = 1 whenever you add a user. If you would, however, want to do it in a single row, well ... it kind of misrepresents the relational model. You could, presumably use the NULL special "value" (essentially, declare it without a value) and then check in your application logic with

WHERE user_id = [uid] OR user_id IS NULL

or some such. I'd prefer keeping the relations intact with the former approach, however; you lose foreign keys (although using NULL won't violate the constraint) and similar constraints if you don't.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜