Listen Software’s How To: Tables

Creating a Table

CREATE TABLE {table_name}
(
   {field1} VARCHAR2(10),
   {field2} NUMBER(10)
)
PCTFREE  30	
PCTUSED  60
TABLESPACE (tablespace_name)	
STORAGE  	
(	  
   INITIAL integer	  
   NEXT    integer
);

Adding a Primary Constraint

ALTER TABLE {A_TABLE} ADD (
   CONSTRAINT {A_TABLE_PK}
   PRIMARY KEY ({A_TABLE_IDX})
   USING INDEX 
   TABLESPACE {MY_TABLESPACE}
   PCTFREE  10
   STORAGE  
   (
   INITIAL 20K
   NEXT    40K
   )
)

Adding a Foreign Key Constraint

ALTER TABLE (table_name) ADD 
   (      	
   CONSTRAINT (foreign key constraint name)
   FOREIGN KEY 
   (field name )      	
   REFERENCES  primary_table_name	
   (
   primary_table_primary_index_field	
   )

The foreign key references a unique key in the primary table. The relation is a one-to-many relationship.

Rebuilding Indexes

alter index {my_index_idx} rebuild;

Does not drop the constraints

Get the Free Newsletter!

Subscribe to Cloud Insider for top news, trends & analysis

Latest Articles