Database Articles
  Home arrow Database Articles arrow Page 2 - Databases and SQL
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Download TestComplete 
Forums Sitemap 
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? 
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

  • 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


    Databases and SQL - Adding Information To A Database


    (Page 2 of 5 )

    One interacts with a database by making queries to the database server. A query is a request to the server to perform some specific action on one or more tables. Such actions could be creating a table, adding information to a table, retrieving information from a table and even dropping tables or deleting entire databases!

    The Structured Query Language (SQL) is a set of commands used to communicate with a database. Its syntax is simple and its queries read very much like natural language.

    Create

    The CREATE command can be used to create new databases and tables. To create a database, issue the CREATE command followed by DATABASE and the database name. SQL statements terminate with a semi-colon.

    CREATE DATABASE myDatabase;

    If there is more than one database available to you, you can select one to work with by issuing the USE command followed by the name of the desired database.

    USE myDatabase;

    To create a table, issue the CREATE command followed by TABLE, the table name, and then in parenthesis a list of field/column names and their corresponding data types. A comma separates each field and data type pair.

    CREATE TABLE addresses
    (last_name VARCHAR(50), first_name VARCHAR(50),
    address VARCHAR(50), city VARCHAR(50), state CHAR(2),
    zip_code CHAR(5));

    CREATE TABLE employees
    (employee_id INTEGER, last_name VARCHAR(50),
    first_name VARCHAR(50), hire_date DATE, notes TEXT);

    The first example creates a table named addresses that stores a person’s name and address. The second example creates a table named employees that stores an employee's identification number, name, hire date and any special comments.

    Different database servers support various types of data such as integers, floating point decimals, dates and binary files. For a complete list of data types available for a particular server, you will need to refer to each server's documentation. There are also many resources available on the Internet.

    Insert

    The INSERT command can be used to add records to a table. To add a record, issue the INSERT command followed by INTO, the desired table, VALUES and then the corresponding values surrounded by parentheses. Commas should separate the values, strings should be quoted and the entire query statement is terminated with a semi-colon.

    INSERT INTO addresses VALUES
    ("Smith", "Harold", "321 Elm St.", "Portsmouth", "RI", "02871");

    INSERT INTO employees VALUES
    (355, "Harold", "Smith", "2003-03-30", NULL);

    The first example adds Harold's information to the addresses table. The second example adds Harold's information to the employees table. NULL is a special keyword used to represent an empty field, so in this case there are no special comments to record.

    More Database Articles Articles
    More By bluephoenix


       · Hi,how can i make severals updates at the same time (nmaybe using while)i...
       · Like most other queries, UPDATE affects all of a table's rows unless you specify...
       · Please, can you help me. I'm very new beginer in php :)There's my problem. I know...
     

    DATABASE ARTICLES ARTICLES

    - More on Query Optimization for Oracle Databa...
    - Query Optimization in Oracle
    - Clusters and Other Data Structures for Oracle
    - Using Indexes with an Oracle Database
    - The Basics of Data Structures in Oracle
    - Oracle Data Structures
    - Best Practices for PL/SQL Variables
    - What`s Code Without Variables?
    - Clauses, Sorting, and SQL Queries
    - The From Clause and SQL Queries
    - Query Primer
    - Full Text Searches and Strings
    - Searching with Strings
    - Pattern Matching with Strings
    - Working with Cases of Strings





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