I was working on a task in which I have to add one new column in my existing table and set its value given by the client which is incremental value to previous records.
Id fname lname No
1 user 1 user 1 5
2 user 1 user 1 6
3 user 1 user 1 7
I was looking for some solution and ended up with following solution which works well for me.
-- Create Table
CREATE TABLE usermaster (
-- Insert 100 Records
) GO 100 -- You can specify any no. of records
-- Add one more column called id using ALTER statement
ALTER TABLE usermaster ADD id INT
-- Update Id column with Increment value
DECLARE @id INT
SET @id = 0 -- you can specify any no. I set it 0 so it start with 1.
SET @id = id = @id + 1
-- check updated table records
Happy Querying 🙂