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

 

posted @ 2017-08-09 14:59  小小高  阅读(1441)  评论(0编辑  收藏  举报