Home arrow BrainDump arrow Page 4 - Beginning SQL

Placing Data into a Database with SQL - BrainDump

It's great to have information organized in a database, but what do you do with it once it's in there? The answer is that you have to get it out again before you can do anything with it. And that's where Structured Query Language (SQL) comes in. Keep reading to learn more.

TABLE OF CONTENTS:
  1. Beginning SQL
  2. Retrieving Data from a Database
  3. The Distinct Statement
  4. Placing Data into a Database with SQL
By: James Payne
Rating: starstarstarstarstar / 14
September 25, 2007

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

All you do is take, take, take. It's not right. The database has emotions too. It has needs. Face it, if your tawdry love affair with the employee database is ever gonna blossom into a real, meaningful relationship (and what man doesn't want that?), then you are going to have to learn how to give a little. Unless you are Chuck Norris. Chuck Norris doesn't give -- he takes.

To insert a new row into a table, you'll need the ever helpful INSERT INTO statement.

INSERT INTO EMPLOYEE

VALUES ('BRUCE', 'LEE', 'SECURITY', $50,000);

This would result in the following row being added to the table:

First Name

Last Name

Position

Salary

Bruce

Lee

Security

$50,000

Note: now that Bruce Lee is added to your Employee list, you do not want to make him mad.

If you ever want to insert a new row of data, but for some reason do not have enough information to fill in every column, the INSERT INTO statement can help with that as well.

INSERT INTO EMPLOYEE (FirstName, LastName)

VALUES ('Bruce', 'Lee');

The above code would insert the first and last name into the table and leave the remaining columns blank, to be filled in when you obtain the remaining information.

The Update Statement

As discussed above, we never put in the rest of Bruce Lee's information, which means good ole' Bruce isn't getting paid this week. And he is mad. Fighting mad, which is really the worst kind of mad for Bruce Lee to be. But never fear, use your fingers of fury to pound out the following code.

UPDATE EMPLOYEE SET SALARY=$50,000

WHERE FirstName='Bruce”;

That's right. I just saved your life. Because now the row will contain Bruce's salary.

But now you've forgotten to add the Position, so Bruce is just walking around being a slacker. If ninjas attack he won't know what to do. Should he fight them off or do their taxes? Never fear. You can update multiple columns with the UPDATE statement.

UPDATE EMPLOYEE

SET SALARY=$50,000, POSITION='Security'

WHERE FirstName='Bruce';

Lastly, the UPDATE command also allows us to insert a whole new column.

UPDATE EMPLOYEE

SET column_name=Whatevernameyouwant

WHERE column_name=whatevervalue

The DELETE Statement

Eventually someone is going to get fired. Or murdered by Bruce Lee (let's face it, the guy is a loose canon). Then it will be time to pull out the old DELETE statement.

DELETE from EMPLOYEE WHERE FirstName='Homer';

This will delete the row containing Homer Sampsons information.

Now in the event that Homer was Bruce Lee's victim, we will have to delete the entire database, due to the impending lawsuits. Here is how we do that:

DELETE * FROM EMPLOYEE;

You can also Delete a column from your table.

DELETE FROM EMPLOYEE

WHERE column_name=whatever_column_you_wish_to_delete;

And that's it for the basics of SQL. Get a little rest and work on that kung-fu grip. The second tutorial in the Beginning SQL series will be coming soon.



 
 
>>> More BrainDump Articles          >>> More By James Payne
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

BRAINDUMP ARTICLES

- Apple Founder Steve Jobs Dies
- Steve Jobs` Era at Apple Ends
- Google's Chrome Developer Tool Updated
- Google's Chrome 6 Browser Brings Speed to th...
- New Open Source Update Fedora 13 is Released...
- Install Linux with Knoppix
- iPad Developers Flock To SDK 3.2
- Managing a Linux Wireless Access Point
- Maintaining a Linux Wireless Access Point
- Securing a Linux Wireless Access Point
- Configuring a Linux Wireless Access Point
- Building a Linux Wireless Access Point
- Migrating Oracle to PostgreSQL with Enterpri...
- Demystifying SELinux on Kernel 2.6
- Yahoo and Microsoft Create Ad Partnership

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: