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

Jignesh TrivediRank #16 · 50.3K reputationPosted Mar 28, 2014, 12:39 AM EDT
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.
Jignesh TrivediRank #16 · 50.3K reputationPosted Mar 28, 2014, 12:42 AM EDT
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.
JAYRAMRank #7,836 · 233 reputationPosted Mar 28, 2014, 12:51 AM EDT
already existing table ..how to add sno
Jignesh TrivediRank #16 · 50.3K reputationPosted Mar 28, 2014, 12:53 AM EDT
hi,
If you want to new column than first solution( add identity column using alter table statement) is good.
hope this will help you.
sudipta sanyalRank #1,945 · 753 reputationPosted Apr 23, 2014, 11:21 PM EDT
select ROW_NUMBER() over(order by id) as Srno, * from your_table
Ranjit PowarRank #553 · 4.4K reputationPosted Apr 24, 2014, 12:42 AM EDT
ALTER TABLE TableName ADD sno INT IDENTITY(1,1)