{C++ etc.}

Latest Posts
 
Home | C++ Posts | Linux Posts | Programming Posts | Issue Tracking Posts

Thursday, May 21, 2009

Altering the primary key of an Oracle Table

Eg: Table T_1 has the following columns:
T_1
--------------
NAME VARCHAR2(100) not null (primary key)
AGE INT
ID VARCHAR2(100)
PASS VARCHAR

NAME is the primary key.
If we want to add INT to the primary key and make it a composite key:
1. We must first make the ID column "not null" which means it could not have any NULL entries.
2. We should drop the existing primary key.
3. Create the new primary key.


PL/SQL script to achive this:

alter table T_1 modify NAME VARCHAR2(100) NOT NULL;
alter table T_1 drop primary key;
alter table T_1 add primary key (NAME, ID);
commit;

:)

No comments: