Home arrow Miscellaneous arrow Oracle Database XE: Tables and Constra...

Oracle Database XE: Tables and Constraints
By: Apress Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1

    Table of Contents:
  • Oracle Database XE: Tables and Constraints
  • Using Constraints



    Oracle Database XE: Tables and Constraints

    (Page 1 of 2 )

    In this fifth part of a seven-part series on using and administering Oracle Database XE, you will learn how to create a table and use constraints. This article is excerpted from chapter 30 of the book Beginning PHP and Oracle: From Novice to Professional, written by W. Jason Gilmore and Bob Bryla (Apress; ISBN: 1590597702).

    Creating a Table

    To create a table you use the CREATE TABLE command. At a minimum, you must specify the column names and their datatypes. You can optionally specify default values and constraints. Alternatively, you can add these later. In this example, you want to create a table for the orders placed on your e-commerce Web page powered by PHP, of course:

    create table customer_order (
         order_id           number,
    customer_id        number,
         order_date         date,
         order_ship_date    date,
         item_qty_num       number,
    ship_notes         varchar2(1000)
    ) tablespace php_apps;

    Notice that we specify the tablespacePHP_APPSexplicitly. Itís optional, and if you want all of your tables to reside in the default tablespaceUSERS, you can leave off theTABLESPACEclause. To see the structure of the table you have just created, you can use theDESCRIBEcommand either in the SQL Commands Web interface or at the Run SQL Command Line prompt accessible from the start menu in Windows:

    describe customer_order

    Name               Null?    Type
    ------------------ -----    ---------------
    ORDER_ID                    NUMBER CUSTOMER_ID                 NUMBER ORDER_DATE                  DATE ORDER_SHIP_DATE             DATE ITEM_QTY_NUM                NUMBER SHIP_NOTES                  VARCHAR2(1000)

    The column in the describe output labeledNull?has a value ofNOT NULLfor table columns that cannot containNULLvalues. Most of the columns in this table should always be provided. We will show you how to require input values for specified columns, and many others, throughout the rest of this chapter.

    Of course, you can also use the Oracle Database XE home page to view this tableís characteristics by navigating to the Object Browser from the Oracle Database XE home page. In Figure 30-2, you can see the structure of the tableCUSTOMER_ORDERand the other operations you can perform on the table.

    Figure 30-2.  Viewing a tableís structure using the Object Browser

    More Miscellaneous Articles
    More By Apress Publishing

    blog comments powered by Disqus


    - Attention: Forum and Site Maintenance
    - Oracle Database XE: Indexes and Sequences
    - Modifying Tables in Oracle Database XE
    - Oracle Database XE: Tables and Constraints
    - More on Oracle Databases and Datatypes
    - Oracle Database XE Datatypes: Datetime and L...
    - Oracle Database XE Datatypes: Character and ...
    - From Databases to Datatypes
    - Firefox 3.6.6 Released with Improved Plug-in...
    - Attention Bloggers: WordPress 3.0 Now Releas...
    - Reflection in PHP 5
    - Inheritance and Other Advanced OOP Features
    - Advanced OOP Features
    - Linux from Scratch V.6.6 Review
    - Linux Gaining in Strength

    Developer Shed Affiliates


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