数据库类型:SqlServer 2012
--检查是否存在发布订阅的系统表
if (select count(*) from sys.tables where name=N'sysarticles' or name= N'syspublications') =2
--存在, 查询数据库 下所有表的 订阅情况
select a.name as 'TableName' , (case when b.artid is null then 0 else 1 end ) as 'IsCheck',c.name as'PublicationName'
from sys.tables a
left join [PhoneAndPic].[dbo].[sysarticles] b on a.object_id=b.objid and b.dest_owner='dbo'
left join [PhoneAndPic].[dbo].[syspublications] c on b.pubid=c.pubid
where a.is_ms_shipped =0
order by c.name desc ;
else
--不存在,只查询普通表
select a.name as 'TableName' , 0 as'IsCheck', ''as'PublicationName'
from sys.tables a
where a.is_ms_shipped =0 ;