473,396 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to make column autoincrement in Oracle 9i

Hi all,
I have table test with fields (ID, Name, Lastname)
ID (number)
Name varchar (15)
Lastname varchar (30)

When I insert record to table I want to be incremented field ID automatically.

Please give me your opinion how can I make ID field autoincrement.

Thanks in advance.
May 15 '07 #1
4 9838
Hi,

Better you write after insert trigger. Why i am telling is once you insert the value in to the table the after insert trigger will be fired and id no will be increment.

Hi all,
I have table test with fields (ID, Name, Lastname)
ID (number)
Name varchar (15)
Lastname varchar (30)

When I insert record to table I want to be incremented field ID automatically.

Please give me your opinion how can I make ID field autoincrement.

Thanks in advance.
May 15 '07 #2
Can you write me step-by-step how can I do it.

Thanks in advance.
May 15 '07 #3
chandu031
78 Expert
Hi all,
I have table test with fields (ID, Name, Lastname)
ID (number)
Name varchar (15)
Lastname varchar (30)

When I insert record to table I want to be incremented field ID automatically.

Please give me your opinion how can I make ID field autoincrement.

Thanks in advance.
Hi,

The only way of implementing an Identity column in Oracle would be to have a
before insert trigger on the table. Here's the syntax for the same:
Expand|Select|Wrap|Line Numbers
  1. CREATE OR REPLACE TRIGGER 
  2. TRIG
  3. BEFORE INSERT ON TEST
  4. FOR EACH ROW
  5. BEGIN
  6. SELECT SEQ.NEXTVAL INTO :NEW.ID FROM DUAL;
  7.  
  8. EXCEPTION 
  9. WHEN OTHERS THEN
  10. RAISE_APPLICATION_ERROR(-20001,SQLERRM());
  11. END;
  12.  
To use this you will have to create a sequence first.

Hope this is helpful.
May 15 '07 #4
Thank you very much
May 15 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: RA | last post by:
Hi I have the following datarow that I want to add to a datatable. DataRow newRow = ds.Tables.NewRow (); newRow = Cache.ToString (); newRow = Cache.ToString (); ds.Tables.Rows.Add...
1
by: Steve Farmer | last post by:
Hi everybody, I have a column in a DataSet (ItemNo) where I need to find out the highest number, so I can add 1 to it when a new record is written to the database. What is the best way to that...
0
by: Benny Raymond | last post by:
reply to: benny@pocketrocks.com if possible: I'm trying to set up a hierarchy system in this database where each row can be related to a previous row. The problem is that when I go to...
1
by: explode | last post by:
My table has 5 columns: Broj iksice, Prezime, Ime, Broj indeksa, Broj pohadjanja. This is the code in the dataset designer VB made it by it self: Private Sub InitClass() Me.columnBroj_iksice =...
4
by: Tim | last post by:
Hello All, I could use some help on an error that is just now popping it's head up. Seems that the autoincrement numeric has hit 32,767. The autoincrement is used in various locations in the...
4
by: jrhitokiri | last post by:
i have been working on a project with an autoincrement column. as i tested continually, the increments reached about 2500. now, with the project finished, how do i reset the autoincrement counter...
1
rizwan6feb
by: rizwan6feb | last post by:
I have a DataTable with thousands of records, i want to show these records on per page basis ( i.e a DataGridView showing first 20 records and next button to show next 20 records ...) To achieve...
1
by: majidkorai | last post by:
Hey Guyz I am having problem when i read the data from a datareader into a data table. The whole scenario is this that I want to read data from two diffrent databases, the table strcutre is...
3
by: Noorain | last post by:
I designed a site. i want to header,footer,left & right column fixed but body information only scrolling. this site screen to be 800/600 px. i designed this way but when i used position fixed all...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.