SHARE
Facebook X Pinterest WhatsApp

Listen Software’s How To: Tables

Apr 23, 2002

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

Recommended for you...

Best Certifications for Database Administrators
Ronnie Payne
Oct 14, 2022
Best Courses for Database Administrators
Ronnie Payne
Jul 22, 2022
TYPE Definition Change in Oracle 21c
Is COUNT(rowid) Faster Than COUNT(*)?
Database Journal Logo

DatabaseJournal.com publishes relevant, up-to-date and pragmatic articles on the use of database hardware and management tools and serves as a forum for professional knowledge about proprietary, open source and cloud-based databases--foundational technology for all IT systems. We publish insightful articles about new products, best practices and trends; readers help each other out on various database questions and problems. Database management systems (DBMS) and database security processes are also key areas of focus at DatabaseJournal.com.

Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.