Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 691739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:34:36+00:00 2026-05-14T02:34:36+00:00

I was wondering… when working with a fixed set of data (say: the population

  • 0

I was wondering… when working with a fixed set of data (say: the population of some cities in a database table CITY_NAME, CITY_POPULATION) that is subject to change which is the best practice?

  1. use an initialization script to populate the table with all possible records and write code to only update the number of citizens for a given city
  2. use “smart” code which can handle the creation of a new record for a previously unaccounted city and update the existing ones instead

In the first case the code will fail if the script hasn’t been run before, in the second case it will certainly be a tad more complicated (and all the queries “show all records” will only list the cities with udated data whereas the in the first case they will at least provide the name of the city with a worrying zero in the “population” field).

Would you go for a cheap but obscure initialization procedure or for more complicated but robust code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T02:34:37+00:00Added an answer on May 14, 2026 at 2:34 am

    If your database has it, I’d use an upsert (called merge in SQL Server 2008, not sure what other dbs might call it)statement, If not I’d roll my own by updating records that had a matching record and inserting records that do not.

    I would not use code I know would fail in predictable circumstances. And in this case, it’s not like the code is even complicated. I could write the whole thing in less than ten minutes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Wondering if anyone has gotten the infamous database is locked error from Trac and
Wondering if there is any way to get the lambda expressions that result from
Wondering what is the best or most popular database client tool. Similar to Microsoft's
Wondering if it is possible to have a version control of a MySQL database.
Wondering if anyone out there can shed some light on why the following regular
Wondering how some of the more experienced (or anyone with a better idea than
Wondering if it's possible to process HAML from database entries. My model currently processes
wondering if there's any way to make it so that a list I have
Wondering if someone can answer something that has stumped me. I have a Timer
Wondering if anyone knows of a set of T4 templates for generating C# POCO

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.