Oracle SQL Developer
Oracle SQL Developer
Oracle SQL Developer
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 Table (Transactions)Name: TransactionsCreate the table columns using the following information. After creating each columnexcept the last one (transaction_type), click Add Column to add the next column. (Ifyou accidentally click OK instead of Add Column, right-click the TRANSACTIONStable in the Connections navigator display, select Edit, and continue to add columns.)Column Name Type Size Other Information and Notestransaction_id NUMBER Primary Key. (Unique transaction ID number,with values to be created using a trigger andsequence that will be created automatically)patron_id NUMBER (Foreign key; must match a patron_id value inthe Patrons table)book_id VARCHAR2 20 (Foreign key; must match a book_id value inthe Books table)transaction_date DATE (Date and time of the transaction)transaction_type NUMBER (Numeric code indicating the type oftransaction, such as 1 for checking out a book)After you have entered the last column (transaction_type), check Show AdvancedOptions (next to Schema). This displays additional tabs for more table options. Forthis table, you will use the Primary Key and Foreign Keys tabs.Primary Key tabBecause you have already specified the column for the primary key, you will use thistab only to specify that the primary key column values are to be populatedautomatically. This convenient approach uses a trigger and a sequence (both createdautomatically by <strong>SQL</strong> <strong>Developer</strong>), and ensures that each transaction ID value isunique.Populate Primary Key Column: TRANSACTION_IDFrom: (Accept the defaults.)Trigger Name: (Either accept the default or enter a name for the before-insert triggerthat will be created automatically.)Foreign Keys tab1. Click Add to create the first of the two foreign keys for the Transactions table.Name: for_key_patron_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: PATRONSReferenced Constraint: Name (generated by <strong>Oracle</strong>) of the primary key constraint forthe Patrons table. (Might be a name with a format like PATRONS_PK.) Be sure that theReferenced Column on PATRONS displayed value is PATRON_ID after you select theReferenced Constraint.Associations: Local Column: PATRON_IDAssociations: Referenced Column on PATRONS: PATRON_ID2. Click Add to create the second of the two foreign keys for the Transactions table.Tutorial: Creating Objects for a Small Database 2-5