Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Auto number on Primary Key

755461Feb 19 2011 — edited Mar 9 2011
Hello All,

I have set up a schema using a DDL script in Oracle 10g. I am linking this through to a Visual Basic 2008 fron end. The connection is fine.
My database of is for a car hire company project.

I need to know how to create an auto increment for a primary key field, like Access does.

For example here is my table structure for my Rental_Payment table.


-- TABLE RENTAL_PAYMENT

CREATE TABLE RENTAL_PAYMENT (
PAYMENTNO NUMBER NOT NULL,
CARDNO NUMBER NOT NULL,
AMOUNT NUMBER NOT NULL,
CARD_TYPE CHAR(20 ) NOT NULL
)
/

-- ADD KEYS FOR TABLE RENTAL_PAYMENT

ALTER TABLE RENTAL_PAYMENT ADD CONSTRAINT KEY6 PRIMARY KEY ( PAYMENTNO )
/



So for example the first record would appear as:

PAYMENTNO CARDNO AMOUNT CARD_TYPE
======== ===== ====== =======
01


I would then enter values and the next payment number would be 02 etc.

PAYMENTNO CARDNO AMOUNT CARD_TYPE
======== ===== ====== =======
01 123412 £40.00 VISA
02


Visual Basic will usually have a star (*) beside a new entry field so 02 will be
| |123412|£40.00|VISA
*|02 | | |

etc........

Thankyou in advance,
OracleTechie
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 6 2011
Added on Feb 19 2011
3 comments
1,165 views