English 中文(简体)
在MySQL的哈希里
原标题:Hashed string in MySQL
  • 时间:2011-11-11 14:45:16
  •  标签:
  • mysql
  • sql

在MySQL中是否存在着某种污点?

请允许我说,我们有一个桌子。

user | action  | target
-----------------------
1    | likes   | 14
2    | follows | 190

I don t want to store "action" as text, because it takes much space and is slow to index. Actions are likely to be limited (up to 50 actions, I guess) but can be added/removed in the future. So I would like to avoid storing all actions by numbers in PHP. I would like to have a table that handles this transparently.

For example, table above would be stored as (1,1,14), (2,2,190) internally, and keys would be stored in another table (1 = likes, 2 = follows).

INSERT INTO table (41, "likes", 153)

这里的“类似”已解决到1个。

INSERT INTO table (23, "dislikes", 1245)

在这里,我们对于在内部增加和储存“类似”没有任何关键。

可能吗?

问题回答

如果你有一套固定(或合理固定)的价值观,那么你就可以使用大田。 它是在内部实施的,因此需要少量磁盘空间。 这里是一个例子:

CREATE TABLE enum_test (
    myEnum enum( enabled ,  disabled ,  unknown )
);

是的,它有这样的顺序:

INSERT INTO table (23, (SELECT id FROM actions WHERE action="dislikes") , 1245)

这样,就能够不从PHP一侧了解该数据库,而只了解行动名称,并继续将它输入数据库,作为ID。

假设你采取行动

id | action
-----------
1  | like
2  | dislike

You want a table called "actions", and a foreign key called "action_id". That is how database normalization works:

用户——行动:

user | action_id  | target
-----------------------
1    | 1          | 14
2    | 2          | 190

行动:

id  | name    
--------------
1   | likes   
2   | follows 

在将<代码>插入用户_actions(1,类似于47)的工作中: 你们应该给予护理。 努力使你坐下来,是毫无道理的;你绝不应在你的申请书中写字。 数据库互动应当由一层模型/商业物体处理,其内部实施应当由您处理。

为使<代码>sert成为用户_actions(1,不相类似,47)自动在<代码>中产生新的记录<>actions。 表: 这再次阻碍了数据库的工作。 你们的榜样应当处理这个问题。





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签