Re: Can someone please tell me...
- From: Paul Clement <UseAdddressAtEndofMessage@xxxxxxxxxxxxxx>
- Date: Tue, 21 Mar 2006 12:28:39 -0600
On Tue, 21 Mar 2006 17:18:45 GMT, newsgroups@xxxxxxxxxxxxxxxx (Martin Aupperle) wrote:
¤ On Tue, 21 Mar 2006 10:07:08 -0600, Paul Clement
¤ <UseAdddressAtEndofMessage@xxxxxxxxxxxxxx> wrote:
¤
¤ >Oracle doesn't implement identity columns, but a sequence number. You create a sequence for a unique
¤ >(primary key) column in a Table. Once the sequence has been created you can query for the next
¤ >sequence number before inserting a new row or include the call to fetch the next sequence number in
¤ >your SQL statement:
¤ >
¤ >CREATE SEQUENCE supplier_seq
¤ > MINVALUE 1
¤ > START WITH 1
¤ > INCREMENT BY 1
¤ > CACHE 20;
¤ >
¤ >INSERT INTO suppliers
¤ >(supplier_id, supplier_name)
¤ >VALUES
¤ >(supplier_seq.nextval, 'Kraft Foods');
¤ >
¤ Thanks. But how do I get the seqeuence number for a newly inserted
¤ record back into my program? Its the primary key!
¤
¤ Tnx - Martin
¤
You will have to query for the next sequence number first. Since only a single value is returned use
ExecuteOracleScalar (for the Oracle provider) or ExecuteScalar (for OleDb).
SELECT supplier_seq.NEXTVAL FROM dual;
Then specify the returned value in your INSERT
"INSERT INTO suppliers
(supplier_id, supplier_name)
VALUES
(" & supplier_seq_number & ", 'Kraft Foods')"
Paul
~~~~
Microsoft MVP (Visual Basic)
.
- Follow-Ups:
- Re: Can someone please tell me...
- From: Martin Aupperle
- Re: Can someone please tell me...
- References:
- Re: Can someone please tell me...
- From: Miha Markic [MVP C#]
- Re: Can someone please tell me...
- From: Martin Aupperle
- Re: Can someone please tell me...
- From: Paul Clement
- Re: Can someone please tell me...
- From: Martin Aupperle
- Re: Can someone please tell me...
- Prev by Date: Slow server performance causes ASP page to Insert duplicate record
- Next by Date: Local SQL Server Express Instance not showing up when getting datasource list
- Previous by thread: Re: Can someone please tell me...
- Next by thread: Re: Can someone please tell me...
- Index(es):
Relevant Pages
|