Generating New Column as Serial Number In Table In MS SQL

main Image
Generating new column as serial number

For generating new column as serial number in output with other column in table.

Syntax for above condition as below:

SELECT @a:=@a+1 serial_number,Columnname
FROM tablename,
(SELECT @a:= 0) AS aliasname;


Consider that we have employee table with column Emp_id,Emp_name,Salary,City and Phone.

Now we can generate six columns in output in which serial number will be your first column by the following query.

SELECT @a:=@a+1 serial_number,Emp_id,Emp_name,Salary,City,Phone
FROM employee,
(SELECT @a:= 0) AS serial_number;


The above query will display generate six columns in output of employee table.

I hope this article will help you.