how to change an existing table column to autoincrement with out affecting the data

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ramyareddy
    New Member
    • Oct 2006
    • 4

    how to change an existing table column to autoincrement with out affecting the data

    Hi All,

    I am using MSSQL 2000 and 2005.
    i have a table memberSecurity with security numer as primary key.
    I have some data in the table already.
    Now i want to make secNo as auto increment and primary key with out affecting the existing data.

    Is there any script that i can run for this?

    Thanks,
    Ramya
  • gahoi
    New Member
    • Aug 2007
    • 5

    #2
    Originally posted by ramyareddy
    Hi All,

    I am using MSSQL 2000 and 2005.
    i have a table memberSecurity with security numer as primary key.
    I have some data in the table already.
    Now i want to make secNo as auto increment and primary key with out affecting the existing data.

    Is there any script that i can run for this?

    Thanks,
    Ramya
    hi
    in table property
    below

    increment property select and change no to yes

    Comment

    • ramyareddy
      New Member
      • Oct 2006
      • 4

      #3
      Hi,

      I CAN DO THAT, but i want query so that i can run it from query analyser.

      any ideas.....


      Ramya

      Comment

      • ck9663
        Recognized Expert Specialist
        • Jun 2007
        • 2878

        #4
        Originally posted by ramyareddy
        Hi,

        I CAN DO THAT, but i want query so that i can run it from query analyser.

        any ideas.....


        Ramya
        alter table. add an integer-IDENTITY column

        Comment

        • ramyareddy
          New Member
          • Oct 2006
          • 4

          #5
          Originally posted by ck9663
          alter table. add an integer-IDENTITY column

          Hi,

          The column is already there in the table. Only thing i have to do is make it auto increment by running some script.

          Ittried with this alter table memberSecurity alter column secNo int IDENTITY(1,1)

          it is giving error Incorrect syntax near the keyword 'IDENTITY'.

          Please tell me where i am wrong, i want to do this by running some script, not from enterprise manager.

          Thanks,
          Ramya.

          Comment

          • rokib hasan

            #6
            SoftEng

            Try This:
            Alter table memberSecurity add column secNo int IDENTITY(1,1)
            primary key

            Comment

            • rokib hasan

              #7
              SoftEng

              sorry for previous reply.
              try this:

              Alter table memberSecurity add secNo int IDENTITY(1,1)
              primary key

              Comment

              Working...