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. Need Help with AUTO_INCREMENT

Need Help with AUTO_INCREMENT

Scheduled Pinned Locked Moved Database
csharpdatabasehelptutorialquestion
5 Posts 2 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.
  • J Offline
    J Offline
    Jethro63
    wrote on last edited by
    #1

    Greetings: I am creating an SQL table programmatically using C#. I have set up my SqlCommand and I am using ExecuteNonQuery to execute the following SQL statement: CREATE TABLE StationData (StnID INT NOT NULL AUTO_INCREMENT, Name CHAR(50), Province CHAR(20), Latitude FLOAT, Longitude FLOAT); This statement is throwing an exception and the exception message says: "Incorrect syntax near "AUTO_INCREMENT"". If I remove the AUTO_INCREMENT specifier from the above statement, then the operation completes successfully and the table and columns are created as expected. It just seems to be that AUTO_INCREMENT specifier. I have checked many similar example statements from various sources and I don't see anything wrong with what I have done here. Any suggestions? Thanks, Mark

    E 1 Reply Last reply
    0
    • J Jethro63

      Greetings: I am creating an SQL table programmatically using C#. I have set up my SqlCommand and I am using ExecuteNonQuery to execute the following SQL statement: CREATE TABLE StationData (StnID INT NOT NULL AUTO_INCREMENT, Name CHAR(50), Province CHAR(20), Latitude FLOAT, Longitude FLOAT); This statement is throwing an exception and the exception message says: "Incorrect syntax near "AUTO_INCREMENT"". If I remove the AUTO_INCREMENT specifier from the above statement, then the operation completes successfully and the table and columns are created as expected. It just seems to be that AUTO_INCREMENT specifier. I have checked many similar example statements from various sources and I don't see anything wrong with what I have done here. Any suggestions? Thanks, Mark

      E Offline
      E Offline
      Eric Dahlvang
      wrote on last edited by
      #2

      Try this:

      CREATE TABLE StationData (StnID INT NOT NULL IDENTITY , Name CHAR(50), Province CHAR(20), Latitude FLOAT, Longitude FLOAT);

      --EricDV Sig--------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters

      J 1 Reply Last reply
      0
      • E Eric Dahlvang

        Try this:

        CREATE TABLE StationData (StnID INT NOT NULL IDENTITY , Name CHAR(50), Province CHAR(20), Latitude FLOAT, Longitude FLOAT);

        --EricDV Sig--------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters

        J Offline
        J Offline
        Jethro63
        wrote on last edited by
        #3

        OK, thanks. It worked. Just wondering, however, IDENTITY seems to have the same effect as AUTO_INCREMENT. What then, is the status of the AUTO_INCREMENT specifier? Obsolete? Why was SQL rejecting it? Thanks, Mark

        E 1 Reply Last reply
        0
        • J Jethro63

          OK, thanks. It worked. Just wondering, however, IDENTITY seems to have the same effect as AUTO_INCREMENT. What then, is the status of the AUTO_INCREMENT specifier? Obsolete? Why was SQL rejecting it? Thanks, Mark

          E Offline
          E Offline
          Eric Dahlvang
          wrote on last edited by
          #4

          MySQL syntax is AUTO_INCREMENT[^] SQL Server is IDENTITY [^]

          --EricDV Sig--------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters

          J 1 Reply Last reply
          0
          • E Eric Dahlvang

            MySQL syntax is AUTO_INCREMENT[^] SQL Server is IDENTITY [^]

            --EricDV Sig--------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters

            J Offline
            J Offline
            Jethro63
            wrote on last edited by
            #5

            I'm going to have to watch out for that. I've seen a lot of web tutorials and references that talk about AUTO_INCREMENT but it turns out that they were all talking about MySQL, not SQL. I had assumed that they would be similar in syntax but this is turning out to be not the case. Thanks again, Mark

            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