Sunday, November 3, 2019

get newly inserted identity column value sql


Table X has as its primary key the column Y which is defined as  int IDENTITY(1,1). After inserting a row into table X, how would you SELECT the newly inserted value of column Y?
Answer:      SELECT IDENT_CURRENT (‘X’) AS Current_Identity;





3.            Table R contains columns ProductID AND OrderDate, amongst others, and contains many rows of data? How would you return just rows 20 to 30 of the data (when ordered by OrderDate and Product ID).
Answer:
SELECT * FROM R order by Product ID, OrderDate  desc LIMIT 19,11

No comments:

Post a Comment