Richie

Sometimes at night when I look up at the stars, and see the whole sky just laid out there, don't you think I ain't remembering it all. I still got dreams like anybody else, and ever so often, I am thinking about how things might of been. And then, all of a sudden, I'm forty, fifty, sixty years old, you know?

Oracle PL/SQL DDL

Table, Field:
Create Table TABLE_NAME(
    COL1 
Integer Default 4 Not Null,
    
Constraint PK_NAME Primary Key(COL1));
Alter Table TABLE_NAME Add(
    COL2 
Decimal Default 0 Null,
    COL3 
Varchar2(20Default ' ' Null,
    COL4 
Integer Not Null);
Alter Table TABLE_NAME Modify (
    COL3 
Varchar2(70Default ' ' Not Null,
    COL4 
Decimal Default 0);
--注意:修改列时如果原来的列已经为Not Null,Modify语句中就只能给Null或者不写是否允许 Null的属性
Alter Table TABLE_NAME Drop (COL3, COL4);
Drop Table TABLE_NAME;
 
Index, Constraint:
Create Index IX_NAME_1 On TABLE_NAME(COL4, COL1)
      Tablespace ERP Storage (Initial 20K 
Next 20k Pctincrease 75);
Drop Index IX_NAME_1;
Alter Table TABLE_NAME Drop Primary Key;
Alter Table TABLE_NAME Add Constraint PK_NAME Primary Key (COL1);
Alter Table TABLE_NAME Add Constraint UK_NAME Unique (COL4, COL3);
Alter Table TABLE_NAME Drop Constraint UK_NAME; 
--or Alter Table TABLE_NAME Drop Unique (COL4, COL3);
 
Sequence:
Create Sequence SEQ_TABLE_NAME Minvalue 1 Maxvalue 999999999999 
      Start 
With 1 Increment By 1 Cache 20;
Alter Sequence SEQ_TABLE_NAME Increment By 5;
Drop Sequence SEQ_TABLE_NAME;
 
Sample Trigger:
Create Or Replace Trigger TR4CRM_SYS_ORG
After 
Insert Or Delete On SYS_ORG --After Update On SYS_ORG
Referencing Old As Old New As New
For Each Row
Declare
   v_count 
Number := 0;
Begin
    
If Inserting Then --insert command
      Select Count(*Into v_count From SYS_ORG_VIEW Where CHILD_ID=:New.ORG_ID;
      
If :New.PARENT_ID>0 Then
              
--sql code
      End If;
      
If :New.ORG_IS_VIRTUAL Is Null Or :New.ORG_IS_VIRTUAL=0 Then
          
--sql code
      End If;
    
End If;
  
  
If Updating And :New.ORG_DEL_FLAG<>:Old.ORG_DEL_FLAG Then --update command
       --sql code
  End If;

    
If Deleting Then --delete command
          Delete From SYS_ORG_VIEW Where PARENT_ID=:New.ORG_ID Or CHILD_ID=:New.ORG_ID;
    
End If;
End;
禁用trigger
alter table PRD_ITEM disable all triggers;
alter table PRD_ITEM enable all triggers;

posted on 2008-10-06 18:15  riccc  阅读(996)  评论(1编辑  收藏  举报

导航