How to check if table exists or Not?

Hi Experts,

I am using SQL DataBase, Before proceed to the next process need to check whether the data table already exists or not IN The part of best practices…

I am using this query:

USE [DB_Name]
GO
IF OBJECT_ID('TableName', 'U') IS NOT NULL
BEGIN
PRINT 'Table exists.'
END
ELSE
BEGIN
PRINT 'Table does not exist.'
END

This query is working absolutely fine in SQL and returning Table exists if already exists…

But my question is it is not working with UiPath

I am using RUN Command to Execute this Query But this is throwing an error that Incorrect Syntax Near GO…

Adding… @Yoichi @ppr @Palaniyappan @lakshman

Regards,
NaNi

Hey Guys!

Found the solution for this:

I Changed the query to:

"IF EXISTS(
SELECT * 
FROM         INFORMATION_SCHEMA.TABLES
WHERE       TABLE_NAME = 'Name')
SELECT 'Found' AS search_result ELSE SELECT 'Not Found' AS search_result;
"

Using RUN Query:

This is giving me the expected output

Regards,
NaNi

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.