declare
mycountINT; begin select count(*) into mycount from user_tab_columns where COLUMN_NAME=‘U_ID‘ AND TABLE_NAME=‘UINFOR‘; if mycount = 0 then --1. 刪除原主鍵 execute immediate ‘alter table uinfor drop constraint PK_uinfor‘; --2. 刪除字段 execute immediate ‘alter table uinfor drop column u_id‘; --3. 添加字段 execute immediate ‘alter table uinfor add u_note varchar(1) NULL‘; --4. 修改字段 execute immediate ‘ALTER TABLE uinfor modify u_key NOT NULL‘; --5. 添加新主鍵 execute immediate ‘alter table uinfor add primary key(u_key ,u_name )‘; end if; end; / |
|