how to retrive row id from a table

  • Hi

    i have a table like following structure

    Roll_No S_Name Subject Branch

    now i need to fetch the record id of this table can any one tell me how can i do so

  • check for Row_number() in BOL.

  • How to do so??

    Can you send me query for this

  • How about some sample data. Please see my first link in the signature below.

  • amitsingh308 (1/18/2010)


    now i need to fetch the record id of this table can any one tell me how can i do so

    What exactly do you mean by Record ID? What are you trying to do here?

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • send some sample data and ur requirement ?

    -------Bhuvnesh----------
    I work only to learn Sql Server...though my company pays me for getting their stuff done;-)

  • As we know that each row have its own id in each table provided by DMBS software. I want to fetch that row ID for specific table

  • SQL Server does not have a 'row ID' assigned to each row by the DB engine. Oracle may (I think), but SQL doesn't.

    What problem are you trying to solve here? I'm sure we can give you an alternative

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • is this what u looking for ?

    create table #tmp

    (

    Roll_No int,

    S_Name nvarchar(100),

    Subject nvarchar(100),

    Branch nvarchar(20))

    insert into #tmp

    select 1 , 'jack', 'Bio', 'A' union

    select 1 , 'alex', 'tech', 'f' union

    select 1 , 'Sona', 'Arts', 'A' union

    select 1 , 'jin', 'Gym', 'b'

    select row_number() over (order by Roll_No ,S_Name ,Subject, Branch ) as ROW_NUMER , *

    from #tmp

    -------Bhuvnesh----------
    I work only to learn Sql Server...though my company pays me for getting their stuff done;-)

  • Actually I went for an interview there interviewer asked me for retrieve row id from a specific table. But I replied so confidently that sql server doesn't assign any Row Id for tables. But I know in Oracle n mysql provides an Id for each row so that I was just conforming is there any thing like that is sql server. So that I asked ?? if there is any then can you tell me how can i retrive row id?

  • amitsingh308 (1/19/2010)


    But I know in Oracle n mysql provides an Id for each row so that I was just conforming is there any thing like that is sql server. So that I asked ??

    SQL Server does not provide an id for a row.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • amar , try to run the script i pasted in my previous past and u will find reply

    -------Bhuvnesh----------
    I work only to learn Sql Server...though my company pays me for getting their stuff done;-)

  • Bhuvnesh (1/19/2010)


    amar , try to run the script i pasted in my previous past and u will find reply

    The Row_Number function is not the same as the RowID that Oracle and MySQL provides.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • can u post the link ? where i can find the difference between them

    -------Bhuvnesh----------
    I work only to learn Sql Server...though my company pays me for getting their stuff done;-)

  • I'd start with google.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 15 posts - 1 through 14 (of 14 total)

You must be logged in to reply to this topic. Login to reply