• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

What is the preferred way of coding the database?

 
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which way do you prefer to code the Database?

1)


2)




Thanks
Jack
 
Bartender
Posts: 2407
36
Scala Python Oracle Postgres Database Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't do "SELECT * FROM customer".

It's quite rare that you really need every column from every record in a given table for a DB application, and fetching unnecessary data just adds extra work and uses up bandwidth. Select specific columns, and only for the records you want i.e. use a WHERE clause wherever possible.

Another problem with "SELECT * ..." is that the table structure may change. Columns may be added/removed from the table, or the column names/data types might change, but there's nothing in your SQL statement to tell the next programmer whether they need to change your SQL to take account of these changes. Make your intentions for your SQL query explicit - select specific columns by name - so that maintaining the program is easier when (not if) the DB changes.
 
Bartender
Posts: 1051
5
Hibernate Eclipse IDE Chrome
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Along with the good advice from Chris, the style of option 2 is definitely the way to go. You don't want calling code to have to know about SQL strings or result sets. It simply needs to provide the ID of the customer to retrieve and the method does the rest.
 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
got it, thanks
 
Weeds: because mother nature refuses to be your personal bitch. But this tiny ad is willing:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic