1、查询目标库中的所有表
SELECT obj.name tablename, ---表名 schem.name schemname, ---表所属的方案 idx.rows, ---一共有几行数组 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 ZC_UAC.sys.objects obj INNER JOIN ZC_UAC.dbo.sysindexes idx ON obj.object_id=idx.id and idx.indid<=1 INNER JOIN ZC_UAC.sys.schemas schem ON obj.schema_id=schem.schema_id where type in(‘U‘) order by obj.name
2、查询目标库中所有的表和视图
SELECT obj.name tablename, ---表名 schem.name schemname, ---表所属的方案 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 ZC_UAC.sys.objects obj INNER JOIN ZC_UAC.sys.schemas schem ON obj.schema_id=schem.schema_id where type in(‘U‘,‘V‘) order by obj.name
时间: 2024-10-26 21:18:11