Need help with server administration?
RSS icon Email icon Home icon
  • Is there a mySQL equiv to SQL Server’s select identity(int,1,1) as …

    Posted on August 30th, 2009 servbit2 No comments

    I’m porting aaaaa project from SQL Server to mySQL.

    In SQL Server:
    “Select identity(int,1,1) as id, a, b, c INTO newTable from oldTable” creates an autoNumbered id column.

    In MySQL: ?

    If there’s no equivalent way, I suppose I could create an empty table with an autoNumber field and then insert into it.

    Actually, it’s a bit of both. Take a look here:

    http://dev.mysql.com/doc/refman/5.1/en/create-table.html#id3240603

    SET @i = 0;
    INSERT INTO ….
    SELECT @i= @i+1 as i, col2 ….

    Leave a reply

    You must be logged in to post a comment.