Doombringer
Doombringer

Reputation: 664

ID of table with multiple data types

I have a small issue, if I were to have a table called, for example, emails that contains emails and user information, how can each email have multiple questions and answers? Do I create a second table with secret questions and answers and use Foreign keyto associate them to each email? If so, do I associate them to each email_name or id?

If it's the latter, when inserting them, would I have to first insert the email and then, in the secret table, insert email_name/id again?

Example:

+----+------------------+----------+------------+----------+-----------------------+---------------+
| id |    email_name    | password |    date    |  ph_num  |    secret_question    | secret_answer |
+----+------------------+----------+------------+----------+-----------------------+---------------+
|  1 | [email protected] |   123456 | 20.03.2013 | 56546513 | Name of first pet?    | Rex           |
|    |                  |          |            |          | Mother's maiden name? | Anna          |
|  2 | [email protected] |  6021512 | 02.06.2015 | 23169584 | Real name?            | Shaquesha     |
|    |                  |          |            |          | First car?            | BMW           |
|  3 | [email protected] |   123564 | 30.07.2008 | 13546849 | Secret number?        | 90321         |
+----+------------------+----------+------------+----------+-----------------------+---------------+

Upvotes: 0

Views: 61

Answers (1)

Jay Parikh
Jay Parikh

Reputation: 2489

I would prefer to create a separate table for questions and answers. And use primary key of emailid table as foreign key in questions table.

Use id as primary key and foreign key in emailid and questions table respectively as id is number and will be storing less memory compare to emailid column.

Upvotes: 1

Related Questions