26.05.2015 Views

o_19m7st4t316nvv6a1bg63l10e4a.pdf

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

criteria you specify.<br />

Let's go back to our example firstname and lastname table – let's say the<br />

table was called 'names'. To get Bob Smith's name in there to begin with, we<br />

would have used SQL that looked like this:<br />

INSERT INTO names VALUES ('Bob', 'Smith');<br />

The ID number would be assigned automatically be the database. Then, later<br />

on, if we wanted to find out who customer 123 was, we could run this SQL:<br />

SELECT * FROM names WHERE id = '123';<br />

This would get us customer 123's record from the database – Bob Smith's<br />

record.<br />

SQL might look complicated, and it can be, but that complexity is helped by<br />

the fact that there aren't very many SQL commands you're likely to ever<br />

need. Really, most websites can get by with just these statements:<br />

CREATE. Used to create new database tables. You have to tell the database<br />

which fields (columns) you want, and what kind of data (text, dates, etc.)<br />

each field is going to contain.<br />

SELECT. This command is used to search tables. You can use operators like =<br />

(equals), < (less than) and > (greater than) to find the record you're after. For<br />

example, if you wanted to find all your sales this week, you would work out<br />

the date a week ago and use SELECT * FROM sales WHERE date > – that is,<br />

"find all records in the sales table where the date is greater than...".<br />

INSERT. Lets you add new records to the table.<br />

UPDATE. Once you've inserted data, update lets you modify parts of it.<br />

Useful if, for example, Bob Smith tells you he'd prefer to be known as Robert<br />

Smith. Update lets you change the data without having to delete and<br />

re-insert it, which means that records get to keep their existing ID nun<br />

DELETE. Removes existing rows from the table, using the same basic syntax<br />

as SELECT.<br />

The Web Design Guide for Newbies |65

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!