Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 how to Increment Data of the Same table with Auto

Author  Topic 

mohan123
Constraint Violating Yak Guru

252 Posts

Posted - 2014-01-03 : 02:03:57
Hello all,

how to Increment Data of the Same table with AutoIncrement .i have a table with 4 columns

id type no amount
1 type1 a1 1000
2 type1 a2 2000
3 type2 b1 3000
4 type3 c1 4000

using Loop how can i increment them to hundered rows same data .

id    type   no     amount
1 type1 a1 1000
2 type1 a2 2000
3 type2 b1 3000
4 type3 c1 4000
5 type1 a1 1000
6 type1 a2 2000
7 type2 b1 3000
8 type3 c1 4000
9 type1 a1 1000
10 type1 a2 2000
11 type2 b1 3000
12 type3 c1 4000

Please suggest me the best using loop

P.V.P.MOhan

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-01-03 : 02:21:04
is the ID column an identity column ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2014-01-03 : 03:40:13
[code]
INSERT INTO Table (type,no,amount)
SELECT t.type,t.no,t.amount
FROM Table t
CROSS JOIN master..spt_values v
WHERE v.type = 'p'
AND v.number BETWEEN 1 AND 99
[/code]
assuming id being identity type

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

mohan123
Constraint Violating Yak Guru

252 Posts

Posted - 2014-01-03 : 04:36:51
how can i insert the 4 records into same table make it as 1 lakh records


P.V.P.MOhan
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2014-01-03 : 04:47:37
quote:
Originally posted by mohan123

how can i insert the 4 records into same table make it as 1 lakh records


P.V.P.MOhan


As i showed
add cross join logic to get it repeated 25000 times (25000 * 4 = 1 lakh)

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -