using auto increment in update

  • I want to insert a record into a table, but have to check the ID of the field against all the existing ID's and if it exists i donot want to insert the record, but i want to create a new record with an ID that is not there and then insert the record. Oracle you can create a sequence on the field and increment by 1 from the previous value, is there something comparable to that in sql, or a better method

    The ID is a alphanumeric fields 15 characters long for every record, a primary ID as well

    any ideas

    thanks

  • In SQL Server we have the identity property, which is numeric only, actually integer only, and GUIDs.

    How do you have an alphanumeric that increases? Does A1 increment to A2? Does A9 increment to B0?

  • Sorry it is a numeric field,

  • The easy way to do this is use the identity property.

    You don't need to insert a value, SQL Server will calculate an incrementing value.

    CREATE TABLE MyBigInt

    (

    MyID bigint IDENTITY(100000000000000, 1)

    , Mychar varchar(10)

    -- column_name data_type,...

    )

    GO

    INSERT MyBigInt SELECT 'A'

    INSERT MyBigInt SELECT 'B'

    SELECT MyID ,

    Mychar

    FROM mybigint

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply