CREATING A DATABASE OBJECT

A database object is everything defined and stored in a database: tables, views, indexes, synonyms, database links, roles, snapshots, users, triggers, packages, procedures and functions

To create a new database object:

First create user:

In SQLPLUS environment:

AN EXAMPLE
CREATE USER &u_name IDENTIFIED BY &u_pass DEFAULT TABLESPACE &def_tbs TEMPORARY TABLESPACE &tmp_tbs QUOTA &u_quota ON "a_tbs;

  • CREATE USER creates a user account that lets you log onto the database. This is the format for the create user command where
    &u_name - user name, &u_pass - password.
  • The DEFAULT TABLESPACE is the tablespace in which the user creates object.
  • The TEMPORARY TABLESPACE is the tablespace in which temprorary objects are created for the user's operations.
  • You can put a QUOTA on either of these tablespaces that limits the amount of space, in bytes, that a user can allocate.

Then run the script like this :

CREATE TABLE software (
  sw_serial_num CHAR(6)       CONSTRAINT sw_pk PRIMARY KEY,
  hw_serial_num CHAR(6)       CONSTRAINT sw_fk 
                              REFERENCES hardware(hw_serial_num),
  name          VARCHAR2(30)  CONSTRAINT sw_name_nn NOT NULL,
  version       VARCHAR2(10),
  purchase_cost NUMBER(8,2),
  purchase_dt   DATE            
);
INSERT INTO SOFTWARE VALUES ('N45-01','95-N45','MS DOS','6.2','','12-OCT-95');                      
INSERT INTO SOFTWARE VALUES ('N45-02','95-N45','MS WINDOWS','3.1','','12-OCT-95');                  
INSERT INTO SOFTWARE VALUES ('N45-03','95-N45','PERSONAL ORACLE7','7.1','','23-NOV-95');            
INSERT INTO SOFTWARE VALUES ('CQ2-01','CQ1002','MS DOS','6.2','','21-OCT-95');                      
INSERT INTO SOFTWARE VALUES ('CQ2-02','CQ1002','MS WINDOWS','3.1','','21-OCT-95');                  
INSERT INTO SOFTWARE VALUES ('CQ2-03','CQ1002','PERSONAL ORACLE7','7.1','','21-OCT-95');            
COMMIT;

  • The word CREATE TABLE tells ORACLE to create a new table named sofrware.
  • In our example primary key is sw_serial_nam. The foreign key is hw_serial_num. This column refers to values for the hw_serial_num column in the hardware table.
  • The command INSERT lets you to place a row of information directly into a table. The VALUE must precede the list of data to be inserted.
  • The ORACLE SQL statement COMMIT makes all changes to data(inserts, updates, deletes) permanent.
  • CHAR, VARCHAR, DATE, NUMBER - are data types.

Also, this script should be expanded by other objects, and should be another script to drop those objects.
A TABLESPACE is an area of disk, usually one disk file. A tablespace can contain many tables, indexes, or clusters (clustering is a method of storing tables that are related and often joined together into the same area on disk).
Until you COMMIT, only you can see how your work affects the table. Anyone else with access to these table will continue to get the old information. Back to SQL/ORACLE overview