How can i effect Autoincrement in my table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sshade25
    New Member
    • Nov 2009
    • 10

    How can i effect Autoincrement in my table

    I created a table of five columns as follows
    crop_id, crop_type, crop_name, cultivation_yrs , local_name.

    I want to make the crop_id to be the primary key, and also to be autoincremental as well as serve as a reference to a foreign key in the main database table which is a different table altogerther.

    I am able to create the primary key and the foreign key but i am not able to achieve the autoincrement

    Please how can i achieve this.
  • rski
    Recognized Expert Contributor
    • Dec 2006
    • 700

    #2
    You can redefine (drop and create again) the table and define the type for column crop_id as 'serial'.
    Or you can create now sequence (CREATE SEQUENCE ,,,) and define default for column crop_id as nextval('seqnec e_name') (ALTER TABLE ..)

    Comment

    Working...