开发者

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

开发者 https://www.devze.com 2023-01-11 03:21 出处:网络
How can I get a list of tables in a database without 开发者_开发知识库a timestamp column? Any suggestions? Using INFORMATION SCHEMA views:

How can I get a list of tables in a database without 开发者_开发知识库a timestamp column?

Any suggestions?


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
  )


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)


You could use OBJECTPROPERTY

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

精彩评论

暂无评论...
验证码 换一张
取 消