SQL: multi valued attributes

后端 未结 4 1193
庸人自扰
庸人自扰 2020-12-31 04:21

I created a table that contains information about a company. One attribute is their telephone number. A company can have many telephone numbers.

How do I create mul

4条回答
  •  佛祖请我去吃肉
    2020-12-31 04:57

    There is generally no such thing as multi-valued attribute in relational databases.

    Possible solutions for your problem:

    1. Create a separate table for storing phone numbers which references your company table by primary key and contains undefinite number of rows per company.

      For example, if you have table company with fields id, name, address, ... then you can create a table companyphones with fields companyid, phone.

    2. (NOT recommended in general, but if you only need to show a list of phones on website this might be an option) Storing telephones in a single field using varchar(...) or text and adding separators between numbers.

提交回复
热议问题