• I can only surmise that this is your blog that you are linking to.

    abhishek_300 (7/27/2015)


    How to get the last record value in sql server without using MAX/TOP clause?

    Solution :

    Using the below query.

    set rowcount 1

    select * from employees order by id desc

    This is making a lot of assumptions here. First of all setting rowcount affects all queries in that connection. Unless you remember to set it back to 0 all subsequent queries will be affected. The bigger issue is that this is not necessarily true. This code is making an assumption that id is an identity column that is always incrementing. If the value for id is set by code or the value is a decrementing identity this code will not return the correct row.

    Here is a working proof.

    create table employees

    (

    id int identity(100, -1)

    , FullName varchar(50)

    )

    insert employees

    select 'I am the oldest.'

    insert employees

    select 'This is the ''newest'''

    select * from employees order by id desc

    1) If a table is having only one identity column how can we insert records into this table?

    By definition you can't have a table with more than 1 identity column. I assume the intention is to state that the table has only 1 column and it is an identity. My argument would be that a table with only a single identity column is not a table and therefore this question is pointless.

    While I applaud the effort I am afraid that the questions are not very robust.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/