Sql Server数据库中表等对象都保存在sysobjects数据表中,临时表被保存于tempdb数据库中
1.判断普通表是否存在,可以使用object_id函数,它可以根据对象名称返回对象的id
if (select object_id(\'TableName\')) is not null select \'true\' else select \'false\'
或者
if exists(select [id] from [sysobjects] where [name]= \'TableName\') select \'true\' else select \'false\'
2.判断临时表是否存在
(1)普通临时表
if (select object_id(\'tempdb..#TempTableName\')) is not null select \'true\' else select \'false\'
(2)全局临时表
if (select object_id(\'tempdb..##TempTableName\')) is not null select \'true\' else select \'fals