Sql Server查询视图和表
SELECT obj.name tablename, CAST ( CASE WHEN (SELECT COUNT(1) FROM sys.indexes WHERE object_id= obj.OBJECT_ID AND is_primary_key=1) >=1 THEN 1 ELSE 0 END AS BIT) HasPrimaryKey from 数据库名.sys.objects obj where type='U' or type='V' order by obj.name