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 |
|
OldMySQLUser
Constraint Violating Yak Guru
301 Posts |
Posted - 2008-02-09 : 14:36:00
|
| How can I delete all the rows in a table except the first six please? |
|
|
cmspot
Starting Member
44 Posts |
Posted - 2008-02-09 : 15:28:15
|
| Delete from aaa where aakeyfield not in (Select top(6) from aaa)I sell my mother in law.Is anybody interested? |
 |
|
|
victory_vishnu
Starting Member
8 Posts |
Posted - 2008-02-09 : 19:57:55
|
| Test AS (SELECT ROW_NUMBER () OVER ( PARTITION BY ID, FNAME , LNAME ORDER BY ID) AS A FROM tbl1 ) DELETE FROM Test WHERE A > 6My Attitude Is My Disguise ... |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-02-10 : 00:12:43
|
| or this:-DELETE tFROM(SELECT ROW_NUMBER() OVER (ORDER BY KeyField) AS RowNo,other fields...FROM Table)tWHERE t.RowNo >6 |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-02-10 : 05:46:35
|
SELECT TOP 6 * INTO #Temp FROM SourceTable ORDER BY SomeColTRUNCATE TABLE SourceTableINSERT SourceTable SELECT * FROM #TempDROP TABLE #Temp E 12°55'05.25"N 56°04'39.16" |
 |
|
|
|
|
|