SQL In Simple English

Inserting, Deleting & Updating

What is the INSERT statement? How do I use it?
The INSERT statement lets you insert information into a database. A few examples are shown below

INSERT INTO people VALUES ('Bush', 'George', 47 , 'White House', 'Washington')
Would insert a new row at the bottom of the table people consisting of the values in parentheses in the above statement.

INSERT INTO people (lastname, city) VALUES ('Gates', 'Redmond')
Would insert a new row at the bottom of the table people consisting of only 2 values as present in the above statement, namely 'Gates' and 'Redmond'. The remaining columns for that particular record would be left empty (null).

Note : A null value is different from 0 or ''(Empty String). A perfect example of this would be a column describing the hair colour for many people. In case the person is bald then the value of the colour should be null rather than empty. This would be perfect from the database design view. A particular entity which doesn't exist should be represented similarly and not by empty Strings.


How do I delete a record from a database?
Use the DELETE statement to remove records or any particular column values from a database.

DELETE FROM people WHERE lastname = 'Hunter'
Would remove the entire record which represents any person whose lastname is 'Hunter'. In our case it would remove 1 record from the sample database table people. It would remove all the values that were a part of that record.


Is there a way to update any record in a database?

Yes. You could use the UPDATE statement. The update statement updates (or replaces) those values that were specified in the SQL statement with the new values provided.

UPDATE people SET age = 50, city = 'Mumbai' WHERE (lastname = 'Hunter' AND firstname='Jason')
Would change Jason Hunter's age from 41 to 50 and would make him shift his residence from 'San Jose' to 'Mumbai'. Isn't that cool?? A new Java Guru is Mumbai !!

You might also like...

Comments

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Java is to JavaScript what Car is to Carpet.” - Chris Heilmann