Sign in to follow this  
YoMan

Database method - which is better?

Recommended Posts

hi im a beginner and i have a question :D i've looked around and seen that most people use SQL servers as database. what makes you choose SQL over normal file database? why work with SQL when u can simply save the data to a file? thanks in advance YoMan

Share this post


Link to post
Share on other sites
The advantage of SQL is that you can execute commands on the database in the form of a query language.

A query is a command that expresses a some action you want to perform on the database, like extracting/inserting/updating/etc. data.

Take a look at this example from Wikipedia:

Quote:

SELECT *
FROM books
WHERE price > 100.00
ORDER BY title;

The following is an example of a SELECT query that returns a list of expensive books. The query retrieves all rows from the books table in which the price column contains a value greater than 100.00. The result is sorted in ascending order by title. The asterisk (*) in the select list indicates that all columns of the books table should be included in the result set.


Queries can be increasingly more complex making them a powerful way access data. They also ensure efficiency in managing/accessing the data.

Share this post


Link to post
Share on other sites
i know sql pritty good, i had exprience in both the methods but i dont understand, why is SQL better? in both methods u can enter and extract data, and if you do the file database wisly it is easier...
why sql?

edit:
isnt sql suppose to be slower then file database? or is it the other way around?
is the fact that you use SQL as query the only reason to choose sql?

Share this post


Link to post
Share on other sites
Safety, concurrency, consistency, integrity, security, load balancing, speed, support, portability, and I'm forgetting another million reasons. In no particular order.

Honestly, a file and a fullblown RDBMS aren't in the same league at all, and aren't used for the same kind of work. If you need a simple local log (for example), there's no reason to use a RDBMS. OTOH, if what you're after is a robust, fault-tolerant, multi-user, concurrent, secure storage system to record sets of entities and their relationships, then you'll likely want a RDBMS, not a flat file.

Share this post


Link to post
Share on other sites
Quote:
Original post by YoMan
i know sql pritty good, i had exprience in both the methods but i dont understand, why is SQL better? in both methods u can enter and extract data, and if you do the file database wisly it is easier...
why sql?

edit:
isnt sql suppose to be slower then file database? or is it the other way around?
is the fact that you use SQL as query the only reason to choose sql?


An SQL database is always faster than a normal file when it comes to accessing/processing non trivial data.

I suggest you look into how a relational database stores information internally. Also look into the fundamental operations a relational database can perform: Namely the join operation. Once you get a clear picture of that, it will be obvious to you why databases are far more efficient than attempting you write your own file access system.

*Note: Databases are only valuable if you have these large "non-trivial" datasets you need to manage.

Share this post


Link to post
Share on other sites
thank you for all the responses !

could anyone mention any functions in the Win32 API that use SQL? (not .NET or MFC)

Share this post


Link to post
Share on other sites
Quote:
Original post by YoMan
thank you for all the responses !

could anyone mention any functions in the Win32 API that use SQL? (not .NET or MFC)

The Win32 API does not do SQL, at least if you don't have a SQL backend. ODBC (a subset of the Win32 API) can log to a backend and issue some SQL commands, but trust me, you don't want to use that.

You'd better use a third party library - SQLite has the advantage to be a local SQL database - data is stored in a file, you don't need any server. This can be a correct solution when you don't have much data; if you have a rather large database, you'd better use a SQL server (in which case I'd give my vote to either PostgreSQL (free software) or MySQL (dual licensing: free software if you are doing some GPLed software; commercial otherwise). Both are pretty good an pretty solid, and both come with their corresponding C API.

HTH,

Share this post


Link to post
Share on other sites
Even when using files locally (save games, for example), data integrity is an issue.

What happens if you're updating a file, and the application crashes? What happens, if you have a hard-core game that only allows save on exit, and the game crashes?

Using transactional database (not server-based, remote, but a local, in-memory one) would ensure that game state is preserved and always correct even in case of a crash.

Files and databases are identical from reliability point of view in case of reliable systems. When dealing with unreliable systems, databases win. Also - there are no reliable systems. This is why all reliable storage relies on database algorithms to provide data integrity.

Let's assume the chances of your save-game failing are 1 in a billion (won't happen, right?).

You sell one million copies of a game. Players, during life-time of the game, will save 250 times each. What's the chance of failure now? For each player, 1 in 4 million. What is the chance of at least one player experiencing the loss? Around 22%

Of course, are the chances of a save-game failing really 1 in a billion?

If you want reliable software, you need to make the chances zero, by applying algorithms that eliminate the problem altogether. Database principles (ACID, for example), are one of these. Whether you then use file system of RDBMS platform is merely a matter of implementation. Existing database implementations just give you all that out-of-box (decades of development and research).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this