add sno 1 to end of the coloum
i have table like ...
400000 laks rows in my table
name address id location
raju hyd 6789 hyd
vamshi vizag 9876 hashinapur
o/p like
i want insert sno coloum and sno 1 to 400000
sno name address id location
1 raju hyd 6789 hyd
2 vamshi vizag 9876 hasthinapur
3
4
5
6
..
.
.
.
.
40000
Loading
Ranjit PowarPosted Apr 24, 2014, 4:42 AM
sudipta sanyalPosted Apr 24, 2014, 3:21 AM
select ROW_NUMBER() over(order by id) as Srno, * from your_table
Jignesh TrivediPosted Mar 28, 2014, 4:53 AM
hi,
If you want to new column than first solution( add identity column using alter table statement) is good.
hope this will help you.
JAYRAMPosted Mar 28, 2014, 4:51 AM
already existing table ..how to add sno
Jignesh TrivediPosted Mar 28, 2014, 4:42 AM
hi,
If you want to logical Sr no than you can use ROW_NUMBER() function
try
create table #temp
(
name varchar(20),
id int
)
insert into #temp values ('Jignesh',123)
insert into #temp values ('Jignesh 1',124)
insert into #temp values ('Jignesh 2',125)
insert into #temp values ('Jignesh 3',126)
select ROW_NUMBER() over(order by id) as Srno, * from #temp
hope this will help you.
Jignesh TrivediPosted Mar 28, 2014, 4:39 AM
hi,
I think, you required new column in physical table right?
using Identity column you can achieve this
try...
create table #temp
(
name varchar(20)
)
insert into #temp values ('Jignesh')
insert into #temp values ('Jignesh 1')
insert into #temp values ('Jignesh 2')
insert into #temp values ('Jignesh 3')
select * from #temp
Alter table #temp Add Id int identity(1,1) not null
hope this will help you.