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  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 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? 
Google.com  
BRAINDUMP

Beginning SQL
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 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:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    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.



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

       

    BRAINDUMP ARTICLES

    - Replacing Oracle with PostgreSQL
    - Demystifying SELinux on Kernel 2.6
    - Yahoo and Microsoft Create Ad Partnership
    - The Advantages of Obscure Open Source Browse...
    - Dell Announces CSI-style Digital Forensics S...
    - Milepost GCC Speeds Open-Source Development
    - Learn These 10 Programming Languages
    - Tomcat Capacity Planning
    - Internal and External Performance Tuning wit...
    - Tomcat Benchmark Procedure
    - Benchmarking Tomcat Performance
    - Tomcat Performance Tuning
    - Wubi: Windows-based Ubuntu Installer
    - Configuring and Optimizing Your I/O Scheduler
    - Linux I/O Schedulers





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek