I would like to save user data in my database. There is common data about the user account (nickname, password, etc.) but also data like firstname, name, age, location, ... How can I manage my data base? Should I create different tables? One containing common user data and another containing all the other data?
Asked
Active
Viewed 333 times
-3
-
I hope that this question/answer could help you http://stackoverflow.com/questions/12318870/when-i-should-use-one-to-one-relationship – hieund Feb 18 '16 at 09:33
-
Thank you, I'm going to read this post ! – Sebna665 Feb 18 '16 at 09:41
3 Answers
1
This is a design choice, and it basically depends on how much information you usually need, and how many extra fields you have.
Option 1: Keep them in the same table, if its not too much or you usually need all the data.
Option 2: Create a User Profile table, that contains the user data that its related to the person and not the account.

Luis Tellez
- 2,785
- 1
- 20
- 28
-
When you write "related to the person and not the account"; what do you mean ? Thanks a lot for your answer, sorry I'm a beginner. :-/ – Sebna665 Feb 18 '16 at 09:40
0
create one single table.
CREATE TABLE `admin`
(
`User_Name` varchar(60) NOT NULL,
`Password` varchar(60) NOT NULL,
'firstname' varchar(60) not null,
'Age' int(11) Not null,
'Location' varchar(50) NOT NULL,
PRIMARY KEY (`User_Name`)
)
ENGINE=InnoDB DEFAULT CHARSET=latin1;

Priyanshu
- 885
- 6
- 12
-
Thanks for you answer. But where can I store the other data ? I don't really understand :-( – Sebna665 Feb 18 '16 at 09:38
0
Create 2 tables: 1. userProfile
create table userProfile(
UserID int primary key auto_increment(1,1),
firstname varchar(50),
age int(11),
location varchar(50));
2.userAccounts:
create table userAccounts(
ID int primary key auto_increment(1,1),
UserID int(11),
UserName varchar(50),
Password varchar(50));
there is a relation between Table1(UserID) and Table2(UserID).

Nabeel
- 147
- 9
-
-
-
ID in userAccount will use to edit or delete specific record. UserID is used to make relation between userProfile and userAccount table. Definitely you will need userId for future transaction like view user info including username and password, this relation is called primary and foreign key relation – Nabeel Feb 18 '16 at 18:45