Tags

, , , , , ,


You can get LAST ROW without using INDEX or IDENTITY COLUMN or TIMESTAMP COLUMN

— FIND OUT LAST INSERTED ROW WITHOUT USING INDEX / IDENTITY COLUMN / TIME STAMP COLUMN


–-Create a table 
CREATE TABLE TestLastQuery
( 
 Name varchar(50),
 Address varchar(70) 
)
GO

  
-–Insert the values

INSERT INTO TestLastQuery ( Name , Address )
VALUES ( 'Pawan' , 'Pune ') 

INSERT INTO TestLastQuery ( Name , Address )
VALUES ( 'Gauri' , 'A Nagar ') 

INSERT INTO TestLastQuery ( Name , Address )
VALUES ( 'Saurabh' , 'A Nagar ') 

INSERT INTO TestLastQuery ( Name , Address )
VALUES ( 'Himanshu' , 'Padmavati ') 

INSERT INTO TestLastQuery ( Name , Address )
VALUES ( 'Rahul W' , ' Jordan') 

  
-– Use the below query to find out the last inserted row

SELECT TOP 1 Name , Address , row_number() over ( order by

( SELECT 2 ) ) AS ROWNUMBER FROM TestLastQuery ORDER BY ROWNUMBER

DESC 

Pawankkmr@gmail.com , Pawan Kumar

Advertisements