判断数据库某字段是否存在
时间:2022-03-14 04:08
更惬意的读、更舒心的写、更轻松的发布
--判断是否存在 if exists(select 1 from master..sysdatabases where name=‘TestDB‘) print ‘TestDB存在‘ else print ‘TestDB不存在‘ --判断表是否存在 if exists(select * from TestDB..syscolumns where id=object_id(‘TestDB.dbo.TestTb‘)) print ‘表TestTb存在‘ else print ‘表TestTb不存在‘ --判断数据中[TestTb]表中是否存在[Name]字段 if exists(select * from TestDB..syscolumns where id=object_id(‘TestDB.dbo.TestTb‘) and name=‘Name‘) print ‘字段Name存在‘ else print ‘字段Name不存在‘
更惬意的读、更舒心的写、更轻松的发布