Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. how to generate ID field with auto numbering

how to generate ID field with auto numbering

Scheduled Pinned Locked Moved Database
tutorialdatabasedesignquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sharp_k
    wrote on last edited by
    #1

    Example:

    Create table myTable(studentID int,
    firstName nvarchar(25),
    lastName nvharchar(23)
    )

    I want the studentID field to be auto generated automatically, like 1,2,3 or 0,1,2 etc each time i insert a record. How do I do that inside a query (not in design mode).

    L R 2 Replies Last reply
    0
    • S sharp_k

      Example:

      Create table myTable(studentID int,
      firstName nvarchar(25),
      lastName nvharchar(23)
      )

      I want the studentID field to be auto generated automatically, like 1,2,3 or 0,1,2 etc each time i insert a record. How do I do that inside a query (not in design mode).

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, this is the SQL statement PHPMyAdmin comes up with when creating a table with two fields, one of them auto-incrementing:

      CREATE TABLE `db1`.`test3` (
      `name` VARCHAR( 12 ) NOT NULL ,
      `ID` INT NOT NULL AUTO_INCREMENT ,
      PRIMARY KEY ( `ID` )
      ) ENGINE = MYISAM

      Hope this helps.

      Luc Pattyn [Forum Guidelines] [My Articles]


      - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


      1 Reply Last reply
      0
      • S sharp_k

        Example:

        Create table myTable(studentID int,
        firstName nvarchar(25),
        lastName nvharchar(23)
        )

        I want the studentID field to be auto generated automatically, like 1,2,3 or 0,1,2 etc each time i insert a record. How do I do that inside a query (not in design mode).

        R Offline
        R Offline
        Reza Raad
        wrote on last edited by
        #3

        If you mean in SQLServer you must use IDENTITY IDENTITY is the auto generate mode of an number field

        Human knowledge belongs to the world http://www.rad.pasfu.com/index.php

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups