zoukankan      html  css  js  c++  java
  • SQL语句判断数据库、表、字段是否存在


    --判断[TestDB]是否存在
    if exists(select 1 from master..sysdatabases where name='TestDB')
        
    print 'TestDB存在'
    else
        
    print 'TestDB不存在'

    --判断表[TestTb]是否存在
    if exists(select * from TestDB..syscolumns where id=object_id('TestDB.dbo.TestTb'))
        
    print '表TestTb存在'
    else
        
    print '表TestTb不存在'

    --判断[TestDB]数据中[TestTb]表中是否存在[Name]字段
    if exists(select * from TestDB..syscolumns where id=object_id('TestDB.dbo.TestTb'and name='Name')
        
    print '字段Name存在'
    else
        
    print '字段Name不存在'
  • 相关阅读:
    事务,视图,索引
    SQL 编辑
    相关子查询
    4
    3
    2
    1
    BaseEditor
    EDCheckPrefabRef
    UIUseImgWindow
  • 原文地址:https://www.cnblogs.com/moss_tan_jun/p/1837933.html
Copyright © 2011-2022 走看看