Monday, October 22, 2012

SQL Features - Primary Key Sequence Handling

When you define a table you can assign a default value to a column based on a sequence.

Steps:
1. Create a Sequence (For ex: empid)
2. Create a table script where primary key column has a default based on the Next Value of the sequence created in Step 1

For Ex:
Create table EMPLOYEES
(EMPID number default empID.NEXTVAL primary key,
column2 columntype);
 

Advantage: No need to create a trigger to fill the column with the next value from a sequence, you just follow above steps.

No comments:

Post a Comment

Provide your thoughts !