dbTalk Databases Forums  

Normalization question

comp.databases comp.databases


Discuss Normalization question in the comp.databases forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
amygdala
 
Posts: n/a

Default Normalization question - 04-15-2007 , 03:15 AM






Hi,

Not too experienced yet when it comes to database normalization. And right
now I'm working on a project in which I would like to have user profiles:

My first impulse was to create a User table, a Person table and a
Person_profile table

The User table would just have the basics for a user to access in the
system:
- id // unique id
- username
- password
- email // needed for registration verification
- active // is user allowed to login?

The Person table would have extended info about that person:
- id // unique id
- user_id // foreign key User.id
- gender
- firstname
- lastname
- birthdate
- phone
- etc..

The Person_profile table would have stuff like:
- id // unique id
- person_id // foreign key Person.id
- image
- url
- description
- active // is user allowed to have a profile
- etc..

This all seemed logic from a perspective that things should be clarifying
and well structured. Also I'm not to thrilled about having too many columns
in one table (possible performance issues?)
But the more I think about it the more I get the feeling that this approach
is unnecessary, because all the information so far still belongs to only one
user.
And from browsing a little through some recent threads in this group I also
got the impression that the id's in each table is overkill too.

What are some of your views on this structure? Insights are much
appreciated.

Cheers.



Reply With Quote
  #2  
Old   
Last Boy Scout
 
Posts: n/a

Default Re: Normalization question - 04-15-2007 , 09:24 PM






amygdala wrote:
Quote:
Hi,

Not too experienced yet when it comes to database normalization. And right
now I'm working on a project in which I would like to have user profiles:

My first impulse was to create a User table, a Person table and a
Person_profile table

The User table would just have the basics for a user to access in the
system:
- id // unique id
- username
- password
- email // needed for registration verification
- active // is user allowed to login?

The Person table would have extended info about that person:
- id // unique id
- user_id // foreign key User.id
- gender
- firstname
- lastname
- birthdate
- phone
- etc..

The Person_profile table would have stuff like:
- id // unique id
- person_id // foreign key Person.id
- image
- url
- description
- active // is user allowed to have a profile
- etc..

This all seemed logic from a perspective that things should be clarifying
and well structured. Also I'm not to thrilled about having too many columns
in one table (possible performance issues?)
But the more I think about it the more I get the feeling that this approach
is unnecessary, because all the information so far still belongs to only one
user.
And from browsing a little through some recent threads in this group I also
got the impression that the id's in each table is overkill too.

What are some of your views on this structure? Insights are much
appreciated.

Cheers.


The e-mail address or maybe the birth of date is one way to look for
duplicates along with the name. In general most sites I have seen key
on only one account per e-mail address. Sometimes a user can forget
their user-name but not their e-mail address, because that is keyed into
their e-mail account. So maybe just using the e-mail address as the key
might be a good idea.


Reply With Quote
  #3  
Old   
Last Boy Scout
 
Posts: n/a

Default Re: Normalization question - 04-15-2007 , 09:28 PM



If you use an ID number as they key, one problem can be looking for
duplicates as you enter the data. This is a problem if the key is a
completely incremented field.

amygdala wrote:
Quote:
Hi,

Not too experienced yet when it comes to database normalization. And right
now I'm working on a project in which I would like to have user profiles:

My first impulse was to create a User table, a Person table and a
Person_profile table

The User table would just have the basics for a user to access in the
system:
- id // unique id
- username
- password
- email // needed for registration verification
- active // is user allowed to login?

The Person table would have extended info about that person:
- id // unique id
- user_id // foreign key User.id
- gender
- firstname
- lastname
- birthdate
- phone
- etc..

The Person_profile table would have stuff like:
- id // unique id
- person_id // foreign key Person.id
- image
- url
- description
- active // is user allowed to have a profile
- etc..

This all seemed logic from a perspective that things should be clarifying
and well structured. Also I'm not to thrilled about having too many columns
in one table (possible performance issues?)
But the more I think about it the more I get the feeling that this approach
is unnecessary, because all the information so far still belongs to only one
user.
And from browsing a little through some recent threads in this group I also
got the impression that the id's in each table is overkill too.

What are some of your views on this structure? Insights are much
appreciated.

Cheers.



Reply With Quote
  #4  
Old   
--CELKO--
 
Posts: n/a

Default Re: Normalization question - 04-16-2007 , 05:26 AM



1) There is no such thing as a magical, universal id that fits onto
everything in creation.

2) The number of columns is determined by the number of attributes you
wish model, so do not split them into multiple tables.

3) Do not write with bit flags; give an active date or status code.

4) And I like the suggestion of using the email address as a key; it
has validation and verification.


Reply With Quote
  #5  
Old   
amygdala
 
Posts: n/a

Default Re: Normalization question - 04-16-2007 , 09:25 AM



* top posting fixed *

"Last Boy Scout" <BadBill (AT) whitehouse (DOT) gov> schreef in bericht
news:FaBUh.1190$7n.877 (AT) newsfe12 (DOT) lga...
Quote:
amygdala wrote:
Hi,

Not too experienced yet when it comes to database normalization. And
right now I'm working on a project in which I would like to have user
profiles:

My first impulse was to create a User table, a Person table and a
Person_profile table

The User table would just have the basics for a user to access in the
system:
- id // unique id
- username
- password
- email // needed for registration verification
- active // is user allowed to login?

The Person table would have extended info about that person:
- id // unique id
- user_id // foreign key User.id
- gender
- firstname
- lastname
- birthdate
- phone
- etc..

The Person_profile table would have stuff like:
- id // unique id
- person_id // foreign key Person.id
- image
- url
- description
- active // is user allowed to have a profile
- etc..

This all seemed logic from a perspective that things should be clarifying
and well structured. Also I'm not to thrilled about having too many
columns in one table (possible performance issues?)
But the more I think about it the more I get the feeling that this
approach is unnecessary, because all the information so far still belongs
to only one user.
And from browsing a little through some recent threads in this group I
also got the impression that the id's in each table is overkill too.

What are some of your views on this structure? Insights are much
appreciated.

Cheers.
If you use an ID number as they key, one problem can be looking for
duplicates as you enter the data. This is a problem if the key is a
completely incremented field.
Thanks for your insights.
I hear you. I would have used UNIQUE KEY `email` (`email`) and UNIQUE KEY
`username` (`username`) though. But using email as primary key is probably
better yeah.

PS.: Please don't toppost, as it makes threads difficult to read.




Reply With Quote
  #6  
Old   
amygdala
 
Posts: n/a

Default Re: Normalization question - 04-16-2007 , 09:33 AM




"--CELKO--" <jcelko212 (AT) earthlink (DOT) net> schreef in bericht
news:1176719210.574486.113260 (AT) e65g2000hsc (DOT) googlegroups.com...
Quote:
1) There is no such thing as a magical, universal id that fits onto
everything in creation.

2) The number of columns is determined by the number of attributes you
wish model, so do not split them into multiple tables.

Alright, I will put all attributes in one table then. It makes sense.


Quote:
3) Do not write with bit flags; give an active date or status code.

What's the reasoning behind this? Is 0 or 1 not a statuscode? (active or
inactive)
The active status should be able to be changed if users are (temporarily)
banned.


Quote:
4) And I like the suggestion of using the email address as a key; it
has validation and verification.

I don't like the idea that throughout the site I would have to address user
profiles as:

http://www.somesite.com/getProfile?e...ress (DOT) com

But, come to think of it, I could use username to serve that purpose of
course.

Cheers




Reply With Quote
  #7  
Old   
Ed Prochak
 
Posts: n/a

Default Re: Normalization question - 04-16-2007 , 01:04 PM



On Apr 16, 10:33 am, "amygdala" <nore... (AT) noreply (DOT) com> wrote:
Quote:
"--CELKO--" <jcelko... (AT) earthlink (DOT) net> schreef in berichtnews:1176719210.574486.113260 (AT) e65g2000hsc (DOT) googlegroups.com...

1) There is no such thing as a magical, universal id that fits onto
everything in creation.

2) The number of columns is determined by the number of attributes you
wish model, so do not split them into multiple tables.

Alright, I will put all attributes in one table then. It makes sense.
Just keep asking the question: is X an attribute of entity Y?
Every time the answer is yes, put it in that entiry. Later you will
split entities according to the Normalizatio rules. So for example, is
phone number an attribute of entity Person? YES
So you add it to the person entity.

Then later when you realize a person can have more than one phone
number. So you create the phone entity and the relation(should have
been a different word) between person and phone. This is about as
simple as an ERD gets.
Quote:
3) Do not write with bit flags; give an active date or status code.

What's the reasoning behind this? Is 0 or 1 not a statuscode? (active or
inactive)
The active status should be able to be changed if users are (temporarily)
banned.
If it is temporary, then when do you restore them? how do you know 1
means banned temporarily for user T but permanently for user Q?

Quote:
4) And I like the suggestion of using the email address as a key; it
has validation and verification.

I don't like the idea that throughout the site I would have to address user
profiles as:

http://www.somesite.com/getProfile?e...ress (DOT) com

But, come to think of it, I could use username to serve that purpose of
course.
What's wrong with it? You might only need it for the inital login.

Ed



Reply With Quote
  #8  
Old   
amygdala
 
Posts: n/a

Default Re: Normalization question - 04-16-2007 , 04:51 PM




"Ed Prochak" <edprochak (AT) gmail (DOT) com> schreef in bericht
news:1176746698.530701.83320 (AT) d57g2000hsg (DOT) googlegroups.com...
Quote:
On Apr 16, 10:33 am, "amygdala" <nore... (AT) noreply (DOT) com> wrote:
"--CELKO--" <jcelko... (AT) earthlink (DOT) net> schreef in
berichtnews:1176719210.574486.113260 (AT) e65g2000hsc (DOT) googlegroups.com...

1) There is no such thing as a magical, universal id that fits onto
everything in creation.

2) The number of columns is determined by the number of attributes you
wish model, so do not split them into multiple tables.

Alright, I will put all attributes in one table then. It makes sense.

Just keep asking the question: is X an attribute of entity Y?
Every time the answer is yes, put it in that entiry. Later you will
split entities according to the Normalizatio rules. So for example, is
phone number an attribute of entity Person? YES
So you add it to the person entity.

Then later when you realize a person can have more than one phone
number. So you create the phone entity and the relation(should have
been a different word) between person and phone. This is about as
simple as an ERD gets.
Alright, gotcha.

Quote:
3) Do not write with bit flags; give an active date or status code.

What's the reasoning behind this? Is 0 or 1 not a statuscode? (active or
inactive)
The active status should be able to be changed if users are (temporarily)
banned.

If it is temporary, then when do you restore them? how do you know 1
means banned temporarily for user T but permanently for user Q?
As far as I thought of it until now, I would use active or inactive only as
a flag that I could be set, predominantly, manualy if a user has paid
contribution. I don't see this project becoming so complex yet to have it
probe any kind of back office application whether or not user X paid the
bill. That's way out of my league.
Good point though, I agree that using merely 0 or 1 is somewhat restrictive.
Although, since I would use char(1) of int(1) it's use could still be easily
expanded right? And since I am going to be the administrator of the site I
know it's meaning.
But let's say I wanted it to be more meaningful or clarifying (for myself or
a future developer) would you advice an enum column in this case?

Quote:
4) And I like the suggestion of using the email address as a key; it
has validation and verification.

I don't like the idea that throughout the site I would have to address
user
profiles as:

http://www.somesite.com/getProfile?e...ress (DOT) com

But, come to think of it, I could use username to serve that purpose of
course.

What's wrong with it? You might only need it for the inital login.

What's wrong with using email as an identifier you mean? If so, let's say I
was user X who wants to visit the profile of user Y: I don't want user X to
know what the email address of user Y is. And since I'm building a site for
which you don't need to be logged in to view ones profile, spamming issues
come to mind here also.

Cheers




Reply With Quote
  #9  
Old   
Gene Wirchenko
 
Posts: n/a

Default Re: Normalization question - 04-17-2007 , 01:08 PM



Last Boy Scout <BadBill (AT) whitehouse (DOT) gov> wrote:

[snip]

Quote:
The e-mail address or maybe the birth of date is one way to look for
duplicates along with the name. In general most sites I have seen key
on only one account per e-mail address. Sometimes a user can forget
their user-name but not their e-mail address, because that is keyed into
their e-mail account. So maybe just using the e-mail address as the key
might be a good idea.
Or not. Sometimes, a couple share an E-mail address.

Sincerely,

Gene Wirchenko

Computerese Irregular Verb Conjugation:
I have preferences.
You have biases.
He/She has prejudices.


Reply With Quote
  #10  
Old   
Ed Prochak
 
Posts: n/a

Default Re: Normalization question - 04-18-2007 , 10:13 AM



On Apr 16, 5:51 pm, "amygdala" <nore... (AT) noreply (DOT) com> wrote:
Quote:
"Ed Prochak" <edproc... (AT) gmail (DOT) com> schreef in berichtnews:1176746698.530701.83320 (AT) d57g2000hsg (DOT) googlegroups.com...

[]

4) And I like the suggestion of using the email address as a key; it
has validation and verification.

I don't like the idea that throughout the site I would have to address
user
profiles as:

http://www.somesite.com/getProfile?e...ress (DOT) com

But, come to think of it, I could use username to serve that purpose of
course.

What's wrong with it? You might only need it for the inital login.

What's wrong with using email as an identifier you mean? If so, let's say I
was user X who wants to visit the profile of user Y: I don't want user X to
know what the email address of user Y is. And since I'm building a site for
which you don't need to be logged in to view ones profile, spamming issues
come to mind here also.

As I said, I was thinking it is only a login ID, so only the owner
would need to know it. Thereafter your have a session ID transmitted
back and forth.

As far as accessing other profiles, that seems to be a new
requirement. It wasn't mentioned in your original post. You need to
think thru your DB access versus your WEB addressing. Or maybe rethink
the email address as PK.

Ed



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.