Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 14th, 2005, 07:05 PM
mikestan21 mikestan21 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 21 mikestan21 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 52 m 7 sec
Reputation Power: 0
Sequence syntax question...

Hi,
I'm trying to create a sequence for a primary key to simply auto-increment by the default of 1.
I have a sql script written to generate mt tables, and I'm not sure how to modify the script to include the sequence. I also just want the sequence for a specific column, ie, PK, not the PK in all tables.

Here's a snippet from my script:

Code:
create table image
(
image_id                int NOT NULL,
source_id               int NOT NULL,
CONSTRAINT image_id_pk PRIMARY KEY (image_id),
CONSTRAINT fk_source_id FOREIGN KEY (source_id) REFERENCES source(source_id)
);


Would I add the create sequence statement right after the create table, and if so, how do I apply the sequence to only 1 table and a single column?

Any help is appreciated,
-mike

Reply With Quote
  #2  
Old March 15th, 2005, 03:29 PM
jim mcnamara jim mcnamara is offline
......@.........
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Posts: 1,308 jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 6 h 19 m 24 sec
Reputation Power: 48
Use NUMBER(15) or something larger for a sequence.

create a sequence which is an object like a table.
Code:
CREATE SEQUENCE MYVALUES;


NB: sequences DO NOT always run consecutively, because users may play with them.
Or delete records from the table, for example.


You put the sequence number in the table when inserting using the NEXTVAL procedure
Code:
INSERT INTO image
(image_id,
source_id ) 
VALUES
( MYVALUES.NEXTVAL,
  123456
);

Reply With Quote
  #3  
Old March 16th, 2005, 12:30 PM
paulh1983 paulh1983 is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Dec 2004
Posts: 1,255 paulh1983 User rank is Sergeant (500 - 2000 Reputation Level)paulh1983 User rank is Sergeant (500 - 2000 Reputation Level)paulh1983 User rank is Sergeant (500 - 2000 Reputation Level)paulh1983 User rank is Sergeant (500 - 2000 Reputation Level)paulh1983 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 15 h 14 m
Reputation Power: 17
create sequence "whatever" start with 1 increment by 1;
if you dont want all your sequences to start with 1, you can change it to 50, or 100 or whatever!

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > Sequence syntax question...


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT