Microsoft SQL — TSQL — How To Check If Field Exists In a Database

Peter Musu`
1 min readJul 30, 2020

--

Microsoft SQL — TSQL — How To Check If Field Exists In a Database

Sometimes you may need to verify if a field (Column) name exists in a table.

Using the query below you may find out if it exists:

IF EXISTS(

SELECT

*

FROM

INFORMATION_SCHEMA.COLUMNS

WHERE

COLUMN_NAME like ‘%Column%’

)

SELECT ‘found’ AS search_result ELSE SELECT ‘not found’ AS search_result;

SELECT

TABLE_NAME,

COLUMN_NAME

FROM

INFORMATION_SCHEMA.COLUMNS

where COLUMN_NAME like ‘%Column%’

Reference: https://chartio.com/learn/databases/using-information-schema-views-to-check-to-see-if-table-exists-in-sql-server/

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response