Home > Database > Mysql Tutorial > 判断数据库某字段是否存在

判断数据库某字段是否存在

WBOY
Release: 2016-06-07 16:12:36
Original
2602 people have browsed it

--判断是否存在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


--判断是否存在
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不存在'
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template