Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Delete all but top 100 rows
Message
De
16/05/2014 14:05:39
Mike Yearwood
Toronto, Ontario, Canada
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2008
Application:
Web
Divers
Thread ID:
01600029
Message ID:
01600124
Vues:
46
>>HI
>>
>>Whats the easiest way to delete all but the top 100 rows from a table.
>>
>>I'm testing somehting but I don't want to shove tens of thousands of records through it yet.
>>
>>Thanks
>>
>>Nick
>
>Other way (if you use SQL Server 2005 and bigger):
>
>DECLARE @Test TABLE (Field int)
>DECLARE @i int
>SET @i = 0
>WHILE @i < 10000
>BEGIN
>  INSERT INTO @Test VALUES (@i)
>  SET @i = @i + 1
>END
>
>SELECT * FROM @Test 
>
>;WITH CTE_Test (Field, RowNo)
>AS
>(
>SELECT Field, ROW_NUMBER() OVER (ORDER BY Field) AS RowNo
>FROM @Test)
>
>DELETE FROM Cte_Test WHERE RowNo > 100
>
>SELECT * FROM @Test 
>
That's nice too!
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform