創建表就不說了。下面開始介紹設置自動增長列。
?1 在表視圖的列上創建。
雙擊表視圖,打開table properties ———>columens ,
雙擊要設置的列(顯示列的序號的那個按鈕,單擊后,會顯示橫向的黑色箭頭)。
打開column properties 對話框。在 ‘general’ 項中,
最下面,找到 sequence,下拉框 后面,有三個按鈕就 ‘create’,‘select’,‘properties’。
新建的話就點擊‘create' 打開 sequence properties 對話框,general 中的name, code 隨意修改
切換到 physical options 項,輸入下面幾項內容
start with 1
increment by 1
minvalue 1
maxvalue 根據自己需要決定是否要設定。沒有的話,選擇 no max value
no cache 勾選
輸入完后,點擊應用。創建完畢。在 preview 中 可以看到相應的創建代碼
同時,在table properties———>preview 的創建代碼中,自動加入了 觸發器trigger 的創建代碼。
創建完成。
使用:到table properties———>preview 中拷貝table 的創建代碼,賦值到plsql中執行。
提示:不知道是我的powerdesigner 設置問題還是怎么回事,table 的創建代碼中沒有自動加入 sequence 的創建部分。
所以,還要到sequence properties ———>preview 中,把sequence的創建代碼拷貝到 表創建的代碼中
放到 cteate table .... 和 create trigger ...中間
例如:
create table G_EC_LotteryCategory? (
?? lcId?????????????? NUMBER(3)?????????????????????? not null,
?? lcName???????????? NVARCHAR2(30),
?? lcAbbr???????????? NVARCHAR2(20),
?? constraint PK_G_EC_LOTTERYCATEGORY primary key (lcId)
)
/
create sequence Sequence_LotCateID
increment by 1
start with 1
?nomaxvalue
?minvalue 1
?nocache;
create trigger tib_g_ec_lotterycategory before insert
on G_EC_LotteryCategory for each row
declare
??? integrity_error? exception;
??? errno??????????? integer;
??? errmsg?????????? char(200);
??? dummy??????????? integer;
??? found??????????? boolean;
begin
??? --? Column lcId uses sequence Sequence_LotCateID
??? select Sequence_LotCateID.NEXTVAL INTO :new.lcId from dual;
--? Errors handling
exception
??? when integrity_error then
?????? raise_application_error(errno, errmsg);
end;
/
在plsql 中執行上端代碼。創建表;
添加記錄測試;
insert into G_EC_LotteryCategory(lcName,lcAbbr) values('1','1');
insert into G_EC_LotteryCategory(lcName,lcAbbr) values('2','2');
查詢后,看到的的id列是自動增長的。
2 先創建,然后在列的sequence 項中選擇。
?在 powerdesigner 左邊的樹中,你的model 項目的子菜單中有 sequence ,右鍵點擊——> new
?打開 sequence properties 對話框,添加內容上面的方法類似。
?完場后,還是到表視圖中,雙擊列名,打開column properties 對話框。
?general——> sequence 的下拉框中就出現了剛才創建的 sequence ,選中,保存即可。
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
