views:

23

answers:

3

How can I get a list of tables in a database without a timestamp column?

Any suggestions?

+4  A: 

Using INFORMATION SCHEMA views:

select * from INFORMATION_SCHEMA.TABLES T where NOT EXISTS 
  (
      select 1 
        from INFORMATION_SCHEMA.COLUMNS 
       where TABLE_CATALOG = T.TABLE_CATALOG
         and TABLE_SCHEMA = T.TABLE_SCHEMA
         and TABLE_NAME = T.TABLE_NAME
         and DATA_TYPE = 'timestamp' -- or the literal representing timestamp data type
  )
Pablo Santa Cruz
Since I'm asking for tables only, I added:and TABLE_TYPE = 'BASE TABLE'Thanks.
DavidStein
+3  A: 

Using SYS.TABLES/SYS.COLUMNS:

SELECT name FROM SYS.TABLES 
 WHERE object_id NOT IN (select object_id 
                           FROM SYS.COLUMNS
                          WHERE system_type_id = 189)
OMG Ponies
A: 

You could use OBJECTPROPERTY

SELECT
    name
FROM
    sys.objects
WHERE
    OBJECTPROPERTY(object_id, 'TableHasTimestamp') = 0 --null if not a table
gbn