Check created tables in SQL database - Advanced Installer Community
jean
Posts: 3
Joined: Wed May 17, 2017 10:38 am

Check created tables in SQL database

Dear Advanced Installer Support Team,

When testing my installer I connected to my local SQL database and created tables in the database by adding SQL script. but after I uninstalled my application and tried to reinstall it, my installer reported the error that xxx table has existed in the database and the installation failed. I think there are two ways to solve it:

1. delete the tables when uninstalling
2. when reinstalling, skip the step to create tables that have existed in my database

which one is better? And how to do it?

Thank you!
Sorin
Posts: 663
Joined: Mon May 08, 2017 1:03 pm

Re: Check created tables in SQL database

Hello and welcome to our forum!

There are indeed two possibilities:
1. delete the tables when uninstalling
This could be done by creating a new SQL script with DROP TABLE query in "SQL Databases" page. Make sure you select the At uninstall option as execution time in the sql script properties.
2. when reinstalling, skip the step to create tables that have existed in my database
You should create an SQL script that first detects if the table exist and if it does, it inserts new rows. Otherwise it creates a new table. A sample SQL code to achieve this would be:

Code: Select all

IF EXISTS (SELECT * FROM Table1 WHERE Column1=’SomeValue’)
    UPDATE Table1 SET (…) WHERE Column1=’SomeValue’
ELSE
    INSERT INTO Table1 VALUES (…)
Please take a look on the following article : SQL: If Exists Update Else Insert
which one is better?
This really depends on your exact scenario. If you need to keep the tables after the install choose the second variant. If the data is not needed after uninstall go with the first.

Hope this helps!

Best regards,
Sorin
Sorin Stefan - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”