Go to home page mail me! RSS Feed
FoxMetrics Web Analytics

Database Design: [Id] vs [Entity][Id]

Tuesday, April 22, 2008 2:01 PM

Ok, developers/dba's give it to me, I've always designed my database tables with a primary key of "Id", so i.e "Products" table will have a primary key column called "Id". However, I've seen other developers/dba's use "ProductId".

In general, I don't really care, however, since I'm a big fan of ActiveRecord and even before that I've always used "Id". Therefore, referencing my object is as easy as "Product.Id" rather than "Product.ProductId" - duplicate information! but my foreign key usually is "ProductId", so you'll see "OrderItems.ProductId" which makes sense to me. My "OrderItems" table will have a foreign key called "ProductId" back to the "Products.Id" column of the "Products" table.

Which method do you prefer?

Your Comments.

  • # re: Database Design: [Id] vs [Entity][Id]

    Gravatardfg

    Left by fdg at 4/22/2008 5:17 PM
  • # re: Database Design: [Id] vs [Entity][Id]

    GravatarI prefer ProductId over Id. But that's more from a database perspective than a .Net perspective. In a database if you're doing a join you end up aliasing Ids all over the place since most tables will have an Id. And if you join ProductId to OrderId you have to prefix it in the Cross Ref table anyway. Tomato Tomatoe...

    Louis
    www.AllStoneTech.com

    Left by Louis at 5/7/2008 9:15 PM

Your Reply.

Comment Form.

Fields denoted with a "*" are required.

You may also like to leave your email or website.

 
Please add 2 and 2 and type the answer here:

Preview Your Comment.

 
Next entries »