Database Articles

  Home arrow Database Articles arrow Page 4 - Databases and SQL
DATABASE ARTICLES

Databases and SQL
By: bluephoenix
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2004-04-19

    Table of Contents:
  • Databases and SQL
  • Adding Information To A Database
  • Retrieving Information From A Database
  • Changing Information In A Database
  • Conclusion

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    Databases and SQL - Changing Information In A Database


    (Page 4 of 5 )

    Occasionally data that is stored in a database may become stale. SQL's DELETE, UPDATE and DROP commands allow you to manage records and keep the information current.

    Delete

    The DELETE command is used to remove records from a table. Issue the DELETE command followed by FROM, the table that holds the records, WHERE and a condition statement that will be used to match the records.

    DELETE from addresses where first_name = "Harold"
    AND last_name = "Smith";

    The example query would remove Harold Smith's record from the addresses table.

    Update

    The UPDATE command can be used to update a record's fields. Issue the UPDATE command followed by the table name, SET, the field names and their new values, WHERE and a condition statement that will be used to match the correct record.

    For example, assume Gwendolyn Adams from our previous examples has decided to move to Milwaukee, WI. Her record in the database needs to be updated to reflect her new address.

    UPDATE addresses SET address = "613 Wright St.",
    city = "Milwaukee", state = "WI", zip_code="53216"
    WHERE (first_name = "Gwendolyn" AND last_name = "Adams");

    The query would update the record in the addresses table for Ms. Adams to store her new address of 613 Write St. Milwaukee, WI, 53216.

    Drop

    When data is no longer needed, the DROP command can be used to delete a table or an entire database. To delete a table, issue the DROP command, followed by TABLE and the name of the table to be dropped.

    DROP TABLE addresses;

    To delete an entire database, issue the DROP command, followed by DATABASE and the name of the database to be dropped.

    DROP DATABASE myDatabase;

    Be careful! Deleting entire tables and databases cannot be undone so one should be extremely cautious when using the DROP command.

    More Database Articles Articles
    More By bluephoenix

    blog comments powered by Disqus

    DATABASE ARTICLES ARTICLES

    - Completing a Book Inventory Management System
    - Uploading Images for a Book Inventory Manage...
    - Finishing the Add Book Story for a Book Inve...
    - Integration Testing for a Book Inventory Man...
    - User Stories for a Book Inventory Management...
    - Unit Testing a Book Inventory Management Sys...
    - Testing a Book Inventory Management System
    - Implementing Models for a Book Inventory Man...
    - Book Inventory Application: Publishers and B...
    - Handling Publishers in a Book Inventory Mana...
    - Publisher Administration for Book Inventory ...
    - Book Inventory Management
    - Using the SQL Reference Manual
    - Using Oracle SQL Developer with SQL Statemen...
    - Fixing Errors with Oracle SQL Developer


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 10 - Follow our Sitemap