Quick Search:
 
 Oracle PL/SQL: Add Primary Key Constraint example Jump to:  
Category: >> Oracle PL/SQL >> Add Primary Key Constraint example  

<< 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


 
   Home |    Search |    Code Library |    Sponsors |    Privacy |    Terms of Use |    Contact Us © 2003 - 2024 psoug.org