UMBC CMSC 461 Spring '99 CSEE | 461 | 461 S'99 | lectures | news | Oracle Help | help

Data Definition Language (DDL)

SQL DDL allows the specification of a set of relations and about each relation:

Data types (Domain types) in standard SQL-92

Null values are a member of all data types.

Data types (Domain types) in Oracle -- Not the same!

Table names can be up to 30 characters long and cannot begin with a number. The table name cannot conflict with another object created in the same user account, and it cannot be the name of an Oracle reserved word.
There can be up to 254 columns for a single table.
Datatypes (only the commonly used ones):

Schema Definition in SQL

We define an SQL relation using the create table command:
create table table_name ( attribute-domain-1,
                          attribute-domain-2, 
                          attribute-domain-3, 
                          ...,
                          attribute-domain-n,
                          integrity-constraint-1, 
                          integrity-constraint-2, 
                          integrity-constraint-3,
                          ..., 
                          integrity-constraint-n )

Integrity constrains

The primary key lists the attributes that form the primary key of the relation. Although the primary key specification is optional, it is generally a good idea to specify one.
The check specifies a condition that must be met by all rows in the table.
It is reasonable to assume that sometimes certain columns might not have a value, there are also times when the database design can not allow the column to be blank. This is done with the "not null" clause. An attempt to add a row with a value missing when it is defined as not null causes the row to be rejected and an error is logged.
One more possibility to mention here is that the attribute can be defined as unique. In that case, only one row may have that specific value. One example of when to use the unique clause if for Social Security numbers.

Examples of creating tables:

    create table customer
    (
        customer_name      char(20) not null,
        customer_street    char(30),
        customer_city      char(30),
        primary key ( customer_name  )
    )

    create table branch
    (
        branch_name        char(15) not null,
        branch_city        char(30),
        assets             number(30,2),
        primary key ( branch-name  )
    )

    create table account
    (
        account_number      char(10) not null,
        branch_name         char(15),
        balance             number(12,2),
        primary key ( account_number  ),
        check ( balance >= 0 )
    )

    create table depositor
    (
        customer-name       char(20) not null,
        account_number      char(10) not null,,
        primary key ( customer-name, account_number  )
    )


CSEE | 461 | 461 S'99 | lectures | news | help

Tuesday, 08-Jun-1999 11:59:47 EDT