开发者

Keeping the data in memory or sql database

I'm trying to learn SQL to store the data rather than reading the file and populating the whole data structure in memory. would it be like reading t开发者_如何学JAVAhe data from disk instead of direct memory?


SQL is a calculus language -- you tell your database manager what you want it to do and it figures out the most efficient way to do it. It will read from disk, but if you access certain information enough, it will cache that data in memory and read from memory. If you access certain things more, a smart RDBMS will figure that out and store those parts in memory and leave the rest on disk. You don't have to worry about where it is getting its information from, just know that it is persistent.


Using a database is, as you say, somewhat like reading the data from disk instead of direct from memory. Many databases provide a way to use SQL to instruct the database on what criteria you want to use in order to search for data. However, unlike using a file to store data, you generally have to do a bit more work to tell the database how you want your data stored, what indexes you want to have created (an index is used by the database to speed up retrievals based on certain fields), where you want to have the data stored (for some databases), etc. A database provides certain key benefits, including atomic transactions (i.e. all database operations (reads, writes, inserts, deletes) that are grouped together in a single transaction with either all succeed together or all fail together, thus simplifying things if something does go wrong), security (you or your database administrator can specify which users can access various pieces of data), and multi-user concurrency (multiple users can access and alter the data simultaneously with minimal interference). For large projects involving a lot of data the use of a database is pretty common, and even small projects can benefit from the use of a database.

Share and enjoy.


Yes, SQL is more like reading and writing to a disk file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜