Why do applications store important data in a database instead of only in program variables?
Options
- Variables are slower to write to than a database is
- Variables live in RAM and vanish at exit; a DB persists (Correct option)
- Databases are required by law for any kind of application
- Variables cannot store text values, only plain numbers
Answer
Variables live in memory (RAM) and disappear when the program stops or restarts; a database saves data on disk so it survives
Why
Memory (RAM) is fast but temporary. If the app restarts or the computer shuts down, everything in variables is gone.
A database writes data to disk, so it persists. That is called persistence.
Many apps combine both: memory or a cache (like Redis) for speed, a database for safety.
Remember
Memory is temporary. Databases persist data.