12.07.2015 Views

Oracle SQL Developer

Oracle SQL Developer

Oracle SQL Developer

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Creating a SequenceName: for_key_book_idReferenced Schema: Name of the schema containing the table with the primary key orunique constraint to which this foreign key refers. Use the schema you have beenusing for this tutorial.Referenced Table: BOOKSReferenced Constraint: Name (generated by <strong>Oracle</strong>) of the primary key constraint forthe Books table. (Might be a name with a format like BOOKS_PK.) Be sure that theReferenced Column on BOOKS displayed value is BOOK_ID after you select theReferenced Constraint.Associations: Local Column: BOOK_IDAssociations: Referenced Column on BOOKS: BOOK_ID3. Click OK to finish creating the table.You have finished creating all the tables. To create a sequence for use in generatingunique primary key values for the Patrons table, go to Creating a Sequence.Related TopicsTutorial: Creating Objects for a Small Database<strong>SQL</strong> <strong>Developer</strong> User Interface2.4 Creating a SequenceCreate one sequence object, which will be used in INSERT statements to generateunique primary key values in the Patrons table. (You do not need to create a sequencefor the primary key in the Transactions table, because you used the <strong>SQL</strong> <strong>Developer</strong>feature that enables automatic population of primary key values for that table.) Youwill use the Create Sequence dialog box to create the sequence declaratively; thesequence that you create will be essentially the same as if you had entered thefollowing statements using the <strong>SQL</strong> Worksheet:CREATE SEQUENCE patron_id_seqSTART WITH 100INCREMENT BY 1;After creating the sequence, you can use it in INSERT statements to generate uniquenumeric values. The following example uses the patron_id_seq sequence in creating arow for a new patron (library user), assigning her a patron ID that is the next availablevalue of the patrons_id_seq sequence:INSERT INTO patrons VALUES (patron_id_seq.nextval,'Smith', 'Jane', '123 Main Street', 'Mytown, MA 01234', null);To create the sequence, if you are not already connected, connect to the database as theuser for the schema you are using for this tutorial. Right-click the Sequences node inthe schema hierarchy on the left side, select Create Sequence, and enter informationusing the Create Sequence dialog box.Schema: Specify your current schema as the schema in which to create the sequence.Name: patron_id_seqIncrement: 1Start with: 1002-6 <strong>SQL</strong> <strong>Developer</strong> Online Help

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!