Database Journal
MS SQL Oracle DB2 Access MySQL PostgreSQL Sybase PHP SQL Etc SQL Scripts & Samples Links Database Forum

» Database Journal Home
» Database Articles
» Database Tutorials
MS SQL
Oracle
DB2
MS Access
MySQL
» RESOURCES
Database Tools
SQL Scripts & Samples
Links
» Database Forum
» Sitemap
Free Newsletters:
DatabaseDaily  
News Via RSS Feed


follow us on Twitter
Database Journal |DBA Support |SQLCourse |SQLCourse2
 

Featured Database Articles

Oracle

Posted Apr 22, 2002

Listen Software's How To: Tables

By David Nishimoto

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



Oracle Archives

Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 




Latest Forum Threads
Oracle Forum
Topic By Replies Updated
Oracle Data Mining: Classification jan.hasller 0 July 5th, 07:19 AM
Find duplicates - Unique IDs Lava 5 July 2nd, 08:30 AM
no matching unique or primary key rcanter 1 April 25th, 12:32 PM
Update values of one table based on condition of values in other table using Trigger Gladiator 3 February 29th, 06:01 PM