Nerveware


The basics

SQL is favored by most programmers but it adds an extra layer of complexity to your code. In order to use databases correctly you should learn the basics manipulating data. To perform queries onto a table you should know the following query types:

Inserting

Inserting data can be done by two different ways. First you'll insert the amount of values equal to the number of columns present in the table. The second inserts the amount of values equal to the number of columns given.

INSERT INTO table VALUES (value_1, value_2, value_n); INSERT INTO table (column_1, column_2, column_n) VALUES (value_1, value_2, value_n);

Your data is stackable also.

INSERT INTO table (column_1, column_2, column_n) VALUES (value_1, value_2, value_n) (value_1, value_2, value_n) (value_1, value_2, value_n);

Updating

After inserting data, you frequently update date with new results. Note the 'where' statement, you will be not the first to update a whole table. The syntax is as followed:

UPDATE table SET column_1 = value_1, column_2 = value_2 WHERE column_3 = value_3;

Selecting

Now there's data to collect, it's time to open the select-can. In the following chapter we'll look deeper into how we retrieve data. For now we'll stick at a simple select.

SELECT column_1, column_2, column_n FROM table; SELECT * FROM table WHERE column_1 = value_1;

Deleting

After some time you may want to delete data. This is strongly discouraged and many database analysts create a 'disabled', 'invisible' or 'deleted' column instead. Set it to 1 (true) and query don't those records.

DELETE FROM table WHERE column_1 = value_1

Coming up: Clauses. Oooh!