Home Forums SQL Server 2008 SQL Server Newbies IDENTITY_INSERT, and Using Alphanumeric Autoincrement Primary Key RE: IDENTITY_INSERT, and Using Alphanumeric Autoincrement Primary Key

  • kiran.vaichalkar (6/1/2013)


    Hi Folks,

    Please help me on below few queries

    My table is

    Users(ID IDENTITY(1,1) PRIMARY KEY, NAME nvarchar(10), MANGER_ID fk_User_id References ID)

    1) now im trying SET IDENTITY_INSERT USERS.ID OFF

    But error message i received is 'Cannot find the object 'Users' because it does not exists or you do not have permissions'.

    2) In case if want my PRIMARY KEY to be alphanumeric as well as autoincrementing. For example the existing values alike 'E1, E2, E3 ans so on.

    Why I am getting that error? and How to eradicate it?

    &

    How to Set our Primary KEY to Alphanumeric AutoIncrementing?

    Kapil answered the question about identity insert.

    You can't have an identity that is a varchar. What are you hoping to gain here by using that type of construct? I would run away from that idea screaming. Keep it simple, go with an int (or bigint) identity and be done with it.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/