可用where條件命令列出所感興趣的對象:
SELECT * FROM sysobjects WHERE xtype = ‘ V ‘
判斷數據庫中是否已經存在某個表,有的話就刪除該表
-- 方法一: if exists ( select * from dbo.sysobjects where id = object_id (N ‘ [dbo].[表名] ‘ ) and OBJECTPROPERTY (id, N ‘ IsUserTable ‘ ) = 1 ) drop table [ dbo ] . [ 表名] -- 方法二: if exists ( select * from sysobjects where id = object_id (N ‘ 表名‘ ) and OBJECTPROPERTY (id, N ‘ IsUserTable ‘ ) = 1 ) drop table [ dbo ] . [ 表名] -- 方法三: if ( Exists ( Select * From SysObjects Where xtype = ‘ U ‘ And Name = ‘ 表名‘ )) drop table [ dbo ] . [ 表名]
註1: N‘‘代表Unicode類型.可以支持不同語種的對象名
註2:OBJECTPROPERTY避免誤刪非使用者創建的資料
OBJECTPROPERTY ( id , property )
id:表示當前數據庫中對象ID的表達式。id是int,並且被假定為當前數據庫上下文中的模式作用域對象。
property:是表示由id指定的對象返回的信息的表達式。
如果為True 回傳 1,如果為Falsec回傳 0。
原文:https://www.cnblogs.com/pyleu1028/p/10436442.html