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
精彩评论