0

I have a Sybase Anywhere database where in I have a table (say Table A). I need to check the ordering of columns within this table. Say if there are 3 columns in table A. Col_1, Col_2 and Col_3

How can I check whether Col_2 comes between Col_1 and Col_3? Basically checking the ordering of columns within a table (if there are more than 3 columns in the table).

Joe Kennedy
  • 9,365
  • 7
  • 41
  • 55
WinSupp
  • 361
  • 2
  • 6
  • 20

1 Answers1

0

You should query the database's system tables that represent the database structure. In SQL Anywhere 8 (last version I know) the interesting tables are SYS.SYSTABLE and SYS.SYSCOLUMN.

This query returns all columns of a table sorted by "logical" order:

SELECT c.column_id, c.column_name
FROM   sys.systable AS t
       INNER JOIN
       sys.syscolumn AS c
       ON c.table_id = t.table_id
WHERE  t.table_name = 'TableA'
ORDER BY c.column_id;

You could query the column_id of Col_2 and check if it is between the column_ids of Col_1 and Col_2.

Oliver Jakoubek
  • 416
  • 1
  • 3
  • 6