Insert Autonumber in table with constrain? |
答題得分者是:Justmade
|
Vashee
初階會員 發表:38 回覆:87 積分:25 註冊:2003-03-31 發送簡訊給我 |
|
timhuang
尊榮會員 發表:78 回覆:1815 積分:1608 註冊:2002-07-15 發送簡訊給我 |
There is no way to set an identity column to store this value. I suggest you other approach to reach this. Create another table no_gen with column PNO (INT), CREATETIME (DATETIME).
Set the column PNO as an identity column. If your original table is ORDERS with column PNO (INT), xxxx (datatype), .....,
Set the column PNO as datatype of char(4) Before you insert a new ORDERS record, insert a new record into table no_gen with: SET NOCOUNT ON;INSERT INTO no_gen (CREATETIME) VALUES (getdate());SELECT @@IDENTITY to get the new PNO value, and then use dephi procedure (sPNO := RightStr('0000' INTTOSTR(iPNO),4)) to fulfill the value with '0' like '0001', '0002' and then insert the ORDERS table with: 'INSERT INTO ORDERS (PNO, XXX1, ...) VALUES ( ' sPNO ', ....... ) This method may not be best, but it works!!
|
Justmade
版主 發表:94 回覆:1934 積分:2030 註冊:2003-03-12 發送簡訊給我 |
In the table / query linking to that autonumber table :
1. double click that table/query
2. in the field editor, right click and select add all fields
3. Click the autonumber field
4. In the property edit, change to event page
5. setup the onGetText Event :
Text := Format('%4.4d',[Sender.AsInteger]);
6. setup the onSetText Event :
Sender.AsInteger := StrToInt(Text); That's it.
|
Vashee
初階會員 發表:38 回覆:87 積分:25 註冊:2003-03-31 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |