|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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 ); |
|
#3
|
|||
|
|||
|
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! |
![]() |
| Viewing: Dev Shed Forums > Databases > Oracle Development > Sequence syntax question... |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|