Quick Search:
CODE
Oracle PL/SQL Code Library
JOBS
Find Or Post Oracle Jobs
FORUM
Oracle Discussion & Chat
 Oracle PL/SQL: Add Primary Key Constraint example Jump to:  
Category: >> Oracle PL/SQL >> Add Primary Key Constraint example Bookmark and Share

<< lastnext >>

Snippet Name: Add Primary Key Constraint example

Description: Example code showing how to add a primary constraint. This Oracle constraint is used to identify the primary key for a table.

A primary key is a single field or combination of fields that uniquely defines a record. None of the fields that are part of the primary key can contain a null value. A table can have only one primary key.

This operation requires that the primary columns are unique, and this Oracle constraint will create a unique index on the target primary key.

Also see:
» Check Constraint - Create
» Unique Constraint
» Primary Key Constraint
» Foreign Key Constraints
» Current_timestamp
» Deferring Constraint Checking
» Constraint Checks
» Add constraint example

Comment: (none)

Language: PL/SQL
Highlight Mode: PLSQL
Last Modified: March 08th, 2009

CREATE TABLE table_name
(column1 datatype NULL/NOT NULL,
column2 datatype NULL/NOT NULL,
...
CONSTRAINT constraint_name PRIMARY KEY (column1, column2, . column_n)
);
 
 
spool pkeys.LOG
 
PROMPT Adding PRIMARY CONSTRAINT TO CT_ADD_NAMES TABLE
 
ALTER TABLE OPS$SQLTIME.CT_ADD_NAMES
DROP PRIMARY KEY
/
 
ALTER TABLE OPS$SQLTIME.CT_ADD_NAMES
ADD CONSTRAINT CT_ADD_NAMES_PK PRIMARY KEY (CT_ID_NO)
USING INDEX 
TABLESPACE CTIDX
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (INITIAL 4096K NEXT 512K MINEXTENTS 1 MAXEXTENTS 100 PCTINCREASE 0 FREELISTS 1)
/
 
spool off


Free
Oracle Magazine
Subscriptions
and Oracle White Papers


SQL University.net courses meet the most demanding needs of the business world for advanced education in a cost-effective manner. SQL University.net courses are available immediately for IT professionals and can be taken without disruption of your workplace schedule or processes.

Compared to traditional travel-based training, SQL University.net saves time and valuable corporate resources, allowing companies to do more with less. That's our mission, and that's what we deliver.

Click here to find out more
 
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 297 users online    © 2009 psoug.org

PSOUG LOGIN
Username: 
Password: 
Forgot your password?