开发者

Hey what is the datatype I am looking for? [closed]

开发者 https://www.devze.com 2023-03-21 07:09 出处:网络
It's difficult to tell what is being asked here. This question is ambiguo开发者_JS百科us, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. F
It's difficult to tell what is being asked here. This question is ambiguo开发者_JS百科us, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

I'm pretty sure it actually exists haha

But in sql it is a field and inside it has data1,data2,data3 and so on. Like an array inside a field. Any idea?


There is no such data type.

You can put data like that in a regular varchar field, but then it will be complicated to use in any query, because there is no built in way to access comma separated items.

The usual way to handle data like that is to put it in another table.


As said befor. No such type.

And you should not keep comma separated values in a field. Instead create another table for the the id-value pairs.

Lets say you have a blog, where you use an Articles table. Each article can have multiple Tags. Instead of keeping all the tags for said article in single field as comma separated values, you should have table structure like this:

 table: Articles         table: Tags         table: ArticleTags
 ----------------        --------------      -----------------
| article_id  PK |      | tag_id    PK |    | article_id   FK |
| title          |      | name         |    | tag_id       FK |
| content        |      |              |    |                 |
|                |       --------------      -----------------
 ----------------

In addition ArticleTags table would have a composite primary key, made from both article and tag ids - PRIMARY KEY( article_id , tag_id ).

0

精彩评论

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