Alter a table to insert primary key and index : Add Primary Key « Constraints « Oracle PL / SQL






Alter a table to insert primary key and index

   
SQL>
SQL> create table inventory(
  2  partno number(4),
  3  partdesc varchar2(35),
  4  price number(8,2),
  5  warehouse varchar2(15));

Table created.

SQL>
SQL> Create index invent_part_loc_idx
  2  On inventory (partno, warehouse);

Index created.

SQL>
SQL>
SQL> Alter table inventory add (
  2  Constraint invent_partno_pk primary key (partno)
  3  Using index invent_part_loc_idx);

Table altered.

SQL>
SQL>
SQL>
SQL> drop table inventory;

Table dropped.

SQL>

   
    
  








Related examples in the same category

1.Add Primary Key
2.Use alter table to add foreign key with cascade delete
3.Use alter table to add foreign key with cascade delete for more than one column
4.Add primary key and try to insert default value to it
5.DUP_VAL_ON_INDEX exception.
6.Alter table to add primary key
7.Alter table to primary key and check it in user_ind_columns and user_cons_columns
8.Joined primary key
9.Add primary key as the last statement
10.Setting primary key as declaring the column