Check if Database table exist on DB - Advanced Installer Community
SingleP
Posts: 11
Joined: Wed Nov 23, 2016 2:21 pm

Check if Database table exist on DB

Hello,

I'm trying to check if selected DB contains specific table.

Scenario: When user install the application, he could decide if create new DB or use existing one.
In case, the user, decide to use an existing DB , i want to check if the selected DB has specific Table on it , or the installer should run SQL script which fills the missing Table.

Looking forward for your reply :)
Horatiu
Posts: 42
Joined: Tue Nov 29, 2016 1:19 pm

Re: Check if Database table exist on DB

Hello SingleP,

The best way to check if you have a specific table is to write an SQL Query in Advanced Installer, and run your custom action depending on its value.
You can find the tutorial for creating the query at the following link: Using an SQL Query to interrogate SQL databases.

Regarding the SQL command, you can try the code below which returns 1 if the table exits and 0 if it doesn't.

IF OBJECT_ID (N'YourTableName', N'U') IS NOT NULL
SELECT 1 AS res ELSE SELECT 0 AS res;

Hope this helps, and have a great day.

Best regards,
~Horatiu
SingleP
Posts: 11
Joined: Wed Nov 23, 2016 2:21 pm

Re: Check if Database table exist on DB

Thank you very much.

Return to “Common Problems”