Looking to learn: SQL in MySQL and SQLlite
Hi,
I'm a long time programmer in C, Python, and a range of other languages. The need has arisen for me to write something that uses a database, and I'm looking for advice on where to start.
A database consists of a collection of tables, and SQL is the language used to create, populate, manipulate, query and destroy the tables and their contents.
Can anyone suggest a non-patronising, information dense tutorial or "How To" guide? Everything I've found from fairly comprehensive searching seems fluffy or way too caught up in its own gravitas.
Suggestions welcome, and thanks in advance.
8 comments
[ 2.3 ms ] story [ 34.8 ms ] threadNote that in practice SQL is a small subset of the languages accepted by MySQL, PostgreSQL, SQLite, Oracle et al. Each defines it's own custom dialect but the concepts are mostly universal.
At first I would use the 'mysql' command-line utility so you can see exactly what's going on; this comes bundled with the installer. Have a think about how your data would fit into rows and columns, but don't over-analyse too much - it takes practice to start thinking in a relational way.
Create your tables and insert some example data. Now in Python connect to your local instance and try querying for some rows (hint: DictCursor is useful, albeit wasteful if you care about performance).
Now read about database normalization and transactions. You should be well on your way!
It would be easy to write a command line for that so I could then experiment. Thoughts?
And any suggestions for guide to SQL syntax and semantics?
Many thanks.
As for syntax and semantics... it's so simple that anything on Google will do. The interesting part is normalization - again I'm sure there's plenty of free guides.
Many thanks for your response.
Good luck!
but if the main functionality of your program is storing data then you are better with something a bit more comprehensive. to be honest, i would suggest postgres over mysql, but either will do. not only as these more feature-complete, but they are much easier to optimise.
also, if you are using python, you might consider sqlalchemy. that can be used as an orm, but is really more like a very neat embedding of sql in python. and it will even let you define your database in python. i think it's very cool. but there's also a risk that you might end up confused about what is sqlalchemy, what is python, and what is sql.
finally, python's documentation for calling sql is not that great. you'll probably end up wanting to read this document - http://www.python.org/dev/peps/pep-0249/