Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

Any suggestions?

like image 294
DavidStein Avatar asked Aug 12 '10 22:08

DavidStein


People also ask

Should all tables have timestamp?

Answers. Yes, your accessement regarding timestamp is correct and you should have it in all tabels in SQL especially if you have Access front end. This will eliminate a possible problem with Access that another user has changed or modified a row since you have opened the record. >>

How do I get a list of columns in all tables?

MyTable) and hit ALT + F1 , you'll get a list of column names, type, length, etc.


2 Answers

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
  )
like image 152
Pablo Santa Cruz Avatar answered Oct 05 '22 11:10

Pablo Santa Cruz


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)
like image 39
OMG Ponies Avatar answered Oct 05 '22 11:10

OMG Ponies