获取表中自增长的列

    技术2022-05-14  7

    //获取表中自增长的列,如果没有返回为 null public static String getSinceColumn(Connection con, String table){  String sinceColumn = null;  try {   String sql = "Select so.name Table_name,sc.name Iden_Column_name,ident_current(so.name) curr_value, "       +    "ident_incr(so.name) incr_value, "       +    "ident_seed(so.name) seed_value "                   +    "from sysobjects so Inner Join syscolumns sc on so.id = sc.id "                +    "and columnproperty(sc.id, sc.name, 'IsIdentity') = 1 "                +    "Where upper(so.name) = upper('"+ table +"') ";   PreparedStatement ps = con.prepareStatement(sql);   ResultSet rs = ps.executeQuery();   while(rs.next()){    sinceColumn = rs.getString(2);   }  } catch (SQLException e) {   // TODO Auto-generated catch block   e.printStackTrace();  }  return sinceColumn; }


    最新回复(0)