龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 数据库类 > Oracle 技术 >

Oracle ID 自增代码的详细介绍

时间:2011-04-12 23:18来源:未知 作者:admin 点击:
分享到:
本文主要是介绍 Oracle ID 自增代码, Oracle ID 自增是计算机的实际应用中经常使用的计算机语言,如果你对其相关的代码感兴趣的话,你就可以点击以下的文章对其进行了解,望你会有所

本文主要是介绍Oracle ID 自增代码, Oracle ID 自增是计算机的实际应用中经常使用的计算机语言,如果你对其相关的代码感兴趣的话,你就可以点击以下的文章对其进行了解,望你会有所收获。

1.创建表

Sql代码

  1. -- Create table   
  2. create table USERS   
  3. (   
  4. ID NUMBER not null,   
  5. USERNAME VARCHAR2(25),   
  6. PASSWORD VARCHAR2(25),   
  7. EMAIL VARCHAR2(50)   
  8. )   
  9. tablespace USERS   
  10. pctfree 10   
  11. initrans 1   
  12. maxtrans 255   
  13. storage   
  14. (   
  15. initial 64K   
  16. minextents 1   
  17. maxextents unlimited   
  18. );   
  19. -- Create/Recreate primary, unique and foreign key 
    constraints   
  20. alter table USERS   
  21. add constraint ID primary key (ID)   
  22. using index   
  23. tablespace USERS   
  24. pctfree 10   
  25. initrans 2   
  26. maxtrans 255   
  27. storage   
  28. (   
  29. initial 64K   
  30. minextents 1   
  31. maxextents unlimited   
  32. );   
  33. -- Create table  
  34. create table USERS  
  35. (  
  36. ID NUMBER not null,  
  37. USERNAME VARCHAR2(25),  
  38. PASSWORD VARCHAR2(25),  
  39. EMAIL VARCHAR2(50)  
  40. )  
  41. tablespace USERS  
  42. pctfree 10  
  43. initrans 1  
  44. maxtrans 255  
  45. storage  
  46. (  
  47. initial 64K  
  48. minextents 1  
  49. maxextents unlimited  
  50. );  
  51. -- Create/Recreate primary, unique and foreign key constraints   
  52. alter table USERS  
  53. add constraint ID primary key (ID)  
  54. using index   
  55. tablespace USERS  
  56. pctfree 10  
  57. initrans 2  
  58. maxtrans 255  
  59. storage  
  60. (  
  61. initial 64K  
  62. minextents 1  
  63. maxextents unlimited  
  64. );  
  65.  

2.创建序列

Sql代码

3.创建触发器

Sql代码

  1. create or replace trigger TRI_USERS_ID   
  2. before insert on users   
  3. for each row   
  4. declare   
  5. -- local variables here   
  6. begin   
  7. SELECT SEQ_USERS_ID.NEXTVAL   
  8. INTO :NEW.ID   
  9. FROM DUAL;   
  10. end TRI_USERS_ID;   
  11. create or replace trigger TRI_USERS_ID   
  12. before insert on users   
  13. for each row   
  14. declare   
  15. -- local variables here   
  16. begin   
  17. SELECT SEQ_USERS_ID.NEXTVAL   
  18. INTO :NEW.ID   
  19. FROM DUAL;   
  20. end TRI_USERS_ID;   
  21. Oracle 11g Multimedia DICOM   

以上就是对Oracle ID 自增的实际应用的代码 的介绍,望你会有所收获。

精彩图集

赞助商链接