Hi
I am curious about pk and names. Some people use ID, other pk etc... Some people use also the table name in their pk name like user_pk, or userpk, or userID, user_id etc...
It's an open discussion, not really a question, so let's start the debate![]()
| SitePoint Sponsor |





Hi
I am curious about pk and names. Some people use ID, other pk etc... Some people use also the table name in their pk name like user_pk, or userpk, or userID, user_id etc...
It's an open discussion, not really a question, so let's start the debate![]()


debate???
name it whatever you like, as long as you don't stick "col" on the front of it
you know, like how some people stick "tbl" on the front of their table names
i like id for PKs and foo_id for related FKs (where foo is the entity)
this way, your sql join conditions look likeCode:customers.id = orders.customer_id





hum... forgive my broken english. I used the wrong word. Let's start the discussion thenOriginally Posted by r937
![]()
Ooh that infuriates me! I know when I'm accessing a column or a table, I don't need Hungarian notation slowing me downOriginally Posted by r937
.
As for primary key conventions, I just use [something]id, where [something] relates to the entity information being stored in the table, like customerid or postid.


Same here. So my joins would look like:Originally Posted by vgarcia
I've never really tried it they way you do Rudy, but i think i like the look of itCode:Customer.CustomerID = Order.CustomerID![]()





the good thing with rudy's solution is that it can save you time with some text editor (not a big amount of time but... still some time)
customer_id
you can cut and paste it easily, just click on the part before the underscore and only that part will be highlighted. That way, you don't always have to rewrite the '_id' part. Can be useful sometimes.





Ditto. Makes it easy to identify the keys on a table.Originally Posted by r937
WishList.com - Universal Gift Registry
KodeFusion.com | AgentOvation | Web Dev Sucess Blog | Net Realty





But in a uniform way throughout your applications.Originally Posted by r937
I tend to go for 'tablename_id'. And the same for the fk. I'm finding it practical to illustrate the join in this way.
Rik
English tea - Italian coffee - Maltese wine - Belgian beer - French Cognac
r937 hit is on the head w/his example...and I too would rather not see "tbl" @ the beginning of table names.My professor actually takes OFF on our assignments if we don't have that prefix on every one of our tables
![]()
![]()
![]()


So he marks you down if you don't prefix every table with tbl_ ?Originally Posted by null
Tell him he's an idiot.


i'm curious, does your professor also prefix his column names with "col"?
just in case, you know, he ever accidentally goes to write a query like
SELECT * FROM colDateAdded
No, he doesn't care about the column names, but he's picky about the table names....but ya, if there is a "Customers" table, he'll take off if we have anything OTHER than "tbl" as the prefix. I totally understand the need for using a common naming convention, that makes perfect sense. I personally use "t" as the prefix...I did this on my last assignment and he deducted 1 point per table. An assignment worth 20 points, 9 tables...I'm sure y'all are qualified enough to do the mathSo he marks you down if you don't prefix every table with tbl_ ?
Tell him he's an idiot.Was the only one that got all the core design and the queries correct, but had one of the lowest grades
![]()





ah man.... that sucks.
tell your teacher to have a little 'discussion' with rudy.....
![]()
Bookmarks