sql语句如何添加一列字段为记录号,oracle中使用select rownum from tablename
即可生成一列字段为记录号码,sql server中的sql怎么写.各位大哥帮忙呀!

解决方案 »

  1.   

    ALTER TABLE 表名称 ADD
    字段名称 numeric(18, 0) NOT NULL IDENTITY (1, 1)
      

  2.   

    IF object_id('Tempdb..#aa') IS not NULL begin drop table #aa end
    SELECT IDENTITY (int, 1, 1) AS a, *
    INTO #aa
    FROM table
    endif
    select * from #aa  
    这样的话就在临时表#aa中有了新的自动累加字段
      

  3.   

    恕小弟无能,我对大哥这句
    SELECT IDENTITY (int, 1, 1) AS a, * INTO #aa FROM table
    还真看不懂
      

  4.   

    如果你就是在dbgrid显示的时候显示一个自增的字段的话还可以
    oncelldraw的事件中
    begin
      if Column.Index = 0 then
        with DBGrid1.Canvas do
        begin
          FillRect(Rect);
          if DBGrid1.DataSource.DataSet.RecNo <> -1 then
            TextOut(Rect.Left + 2, Rect.Top + 2, IntToStr(DBGrid1.DataSource.DataSet.RecNo));
        end;