BrainDump
  Home arrow BrainDump arrow Page 4 - Beginning SQL
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Actuate Whitepapers 
VeriSign Whitepapers 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
IBM developerWorks
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
BRAINDUMP

Beginning SQL
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 12
    2007-09-25

    Table of Contents:
  • Beginning SQL
  • Retrieving Data from a Database
  • The Distinct Statement
  • Placing Data into a Database with SQL

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Beginning SQL - Placing Data into a Database with SQL


    (Page 4 of 4 )

    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.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · SQL is probably one of my favorite computer subjects to write about and the one I...
       · We offer a suggestion for clarification of using the delete function:The current...
     

       

    BRAINDUMP ARTICLES

    - More Amazing Things to Do With Pipelines
    - Pipelines Can Do Amazing Things
    - Better Command Execution with bash
    - Executing Commands with bash
    - Outsourcing: the Hoopla, the Reality
    - MySQL Plays in the Sun
    - All About SQL Functions
    - SQL: Functioning in the Real World
    - More Advanced SQL Statements
    - Beginning SQL the SEQUEL: Working with Advan...
    - Beginning SQL
    - A Look at the VI Editor
    - A Quick Tour of Boo
    - Book Review: Open Source Licensing
    - PGP and GPG: Email for the Practical Parano...

    BlackBerry VTS




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway