c 如何確定資料庫當中是否存在表

2021-04-13 22:43:30 字數 758 閱讀 6307

一:

如果你的資料庫是

sql   server,

則sql

語句為:  

if   exists(   select   1   from   sysobjects   where   name='

你的表名

'   and   xtype='u') 二:

如果是sqlserver

的庫select   *   from   dbo.sysobjects   where   id   =   object_id(n'[dbo].[

表名]')   and   objectproperty(id,   n'isusertable')   =   1)  

如果有結果返回測表存在 三:

oledbconnection.getoledbschematable

可以獲取資料庫中的所有表的資訊 四:

如果是sqlconnection(

只能與sql   server相連)

,你可以通過查詢系統表的方法來找到。

select   name   from   sysobjects   where   name='tablename'  

sqlcommand.execnoquery() 五:

select   *   from   sysobjects   where   name='

你的表名

'   and   xtype='u'  

選出該錶在系統中的記錄,沒有記錄數為0

如何判斷資料庫是否存在

在建立資料庫時,經常要判斷伺服器中是否存在某個資料庫,然後再決定是不是要進行下一步操作。以下是一些簡單地示例,希望會有用。2 ifexists select from master.dbo.sysdatabases where name skybusiness 3 begin4 drop datab...

如何判斷資料庫,表或字段是否存在

在新增新的資料庫,表或字段的時候,新增之前一般都會檢查是否已經存在,這樣做的好處是保證指令碼的穩定性,再次執行的時候也不會報錯了。有兩種方法,一種是使用內建的函式,另外一種是查詢系統表,總結的sql指令碼如下。1 usemaster 2go 34 判斷資料庫是否存在5 方法1 使用函式db id6i...

node從資料庫查詢指定資料是否存在 持續更新

準備 1.已經封裝好的連線資料庫和進行操作的mongoose.js 鏈結 2.本次使用的 查資料庫是否存在資料 const dbclient require dirname mongoose class main find 檢測型別if table instanceof string dbname ...