2015-11-07 22 views
0

定義的數據類型我是mysql新手,我知道mysql中的基本數據類型。我正在使用它來創建一個webapp。mysql usr爲表

我想創建一個表,其中一個特定的字段可以有值列表。例如: UserDB(ID,名稱,list_of_phone_numbers,list_of_interests)。

在上例中,

1)名稱只能有1個。但可以有多個電話號碼。如何在同一行/記錄中爲'用戶'創建電話號碼列表。 2)電話號碼也可以有不同的部分,即ISD代碼,STD代碼等。

換句話說,我可以有用戶定義(使用基本數據類型創建)數據類型作爲表字段嗎?在C/C++中是否有像'結構'?

回答

0

您可以使用聯結表創建電話號碼列表,每個電話號碼和用戶一行。它可能是這個樣子:

create table UserPhones (
    UserPhoneId int not null auto_increment primary key, 
    UserId int not null references Users(UserId), 
    PhoneTypeId int not null references PhoneTypes(PhoneTypeId), 
    PhoneNumber varchar(255), 
    constraint unq_userid_phonetype unique (UserId, PhoneTypeId), 
    constraint unq_userid_phonenumber unique (UserId, PhoneNumber) 
); 

PhoneType將包含像「家」,「工作」,「手機」,「Skype的」,或什麼東西的參考表。