In SQL Server 2000, how to delete the specified rows in a table that does not have a primary key?

Posted by Yousui on Stack Overflow See other posts from Stack Overflow or by Yousui
Published on 2011-01-07T04:11:56Z Indexed on 2011/01/07 4:53 UTC
Read the original article Hit count: 148

Filed under:
|
|

Hi,

Let's say we have a table with some data in it.

IF OBJECT_ID('dbo.table1') IS NOT NULL
BEGIN
    DROP TABLE dbo.table1;
END
CREATE TABLE table1 ( DATA INT );

---------------------------------------------------------------------
-- Generating testing data
---------------------------------------------------------------------
INSERT INTO dbo.table1(data)
SELECT 100
UNION ALL
SELECT 200
UNION ALL
SELECT NULL
UNION ALL
SELECT 400
UNION ALL
SELECT 400
UNION ALL
SELECT 500
UNION ALL
SELECT NULL;

How to delete the 2nd, 5th, 6th records in the table? The order id defined by the following query.

SELECT  data
FROM    dbo.table1
ORDER BY data DESC;

Note, this is in SQL Server 2000 environment.

Thanks.

© Stack Overflow or respective owner

Related posts about tsql

Related posts about sql-server-2000