Wednesday, August 12, 2009

1:1 Relationships

So, I'm writing this Student Programmer Orientation and Training (SPOT) program for work. I'm at a part where I am writing some basics about database design. Specifically I'm writing about relationships. More specifically I'm writing about 1:1 relationships.

The issue is this: 1:1 relationships are really the most complicated IMO. They can be done either like 1:N, or like N:N. Of course when you use a third table to describe the relationship (like N:N) this is more normalized. But using a foreign key, like in a typical denormalized 1:N, is much more common.

At first I didn't realize this. I though, "oh, I'll start with 1:1, go to 1:N, and then do N:N." But I ended up just moving 1:1 to the end, since it could be done like either of the other two. I realize now I left out the part where a 1:N relationship can be described with a third table, but maybe I'll put that in a quiz to see if they can figure it out on their own. (smirk)

Also, its kind of hard to come up with examples, in my opinion. I used Oregon Drivers License record and Social Security record as my two records that have a one to one relationship. Since ODL will only be associated with one SSN, and they won't issue an ODL to someone who has a SSN with an ODL already associated with it, this is perfect.

And I've only written one program that actually uses a table with a 1:1 relationship. I guess its common to use when you have a special group of users. I might have to go back and do that. User ID foreign key . . . reason for being serperate from the rest of the table . . . sounds good to me.

Anyways,
:p

Tuesday, June 30, 2009

Rant # 1

I really love consistency in my program variables. I'm writing in PL/SQL at work now, and our convention is to use pvariablename for all of our procedure parameters. Then we use vvariablename for all of our in procedure variables. It really pisses me off when I'm working on a project with a coworker and she uses a liberal mix of variables starting with p and parameters starting with v.

Also, I really like to handle all my error checking, parsing and stuff on the database side. And she likes to do everything in JavaScript. And our forms are inconsistent. I use three input boxes for a phone number, but she uses 1, with lots of JavaScript control. Again, I control error checking on the server side here, not in JavaScript on the client side.

I think that either way is fine really. I just think that when building a program/website, we should pick a method to do something and use it everywhere instead of just having two or three different types of phone number input fields depending on which part of the app you are looking at.

I bet there are a lot of blogs like this. I seem to get this feeling of frustration quite often while programming, and I'm at a computer with web access, and blogger makes it pretty easy to start a new blog if you want. Lately its almost like, instead of just posting a new blog entry, I'll just make a whole new blog... Should have some option to auto-link all of your blogs if you chose... Maybe I'll build that feature for mine...

Enjoy!