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.
| Author |
Topic |
|
schinni
Yak Posting Veteran
66 Posts |
Posted - 2003-03-10 : 19:07:39
|
| I have a table which is very huge so i want to delete or selectthe rows based on row count,i am wondering if that is possibleexample some thing like theseselect * from tabnamewhere coun(*)> 200000that is my idea |
|
|
chadmat
The Chadinator
1974 Posts |
Posted - 2003-03-10 : 23:56:47
|
| What is the rank based on?You could do:select top 200000 * from tabname But i'm not sure if that's what your asking-Chad |
 |
|
|
Bambola
Posting Yak Master
103 Posts |
Posted - 2003-03-11 : 02:33:15
|
| set rowcount 200000select * from tabname set rowcount 0Same goes for delete.Bambola. |
 |
|
|
schinni
Yak Posting Veteran
66 Posts |
Posted - 2003-03-12 : 19:50:22
|
| Bambola,That is exactly what i want,Thanks very much |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2003-03-12 : 20:02:38
|
| Here is some useful code if you want to delete a bunch of records but in batches instead of all at once:DECLARE @cnt intSELECT @cnt = count(*) FROM Table1WHERE datecolumn < (getdate() - 180) --get the countSET ROWCOUNT 2000 --only process 2000 records at a timeWHILE @cnt <> 0 BEGIN --the actual code would go here DELETE FROM Table1 WHERE datecolumn < (getdate() - 180) SELECT @cnt = count(*) FROM Table1 WHERE datecolumn < (getdate() - 180) --get the count again ENDSET ROWCOUNT 0Tara |
 |
|
|
|
|
|