Toad World® Forums

Generate SQL code

Hi, I want generate a SQL Code with clause “IF NOT EXISTS” into CREATE TABLE statements.

How can I make this?

Thanks! :slight_smile:

Hello Andrew,

Unfortunately you forgot to write DB platform and TDM version. I suppose that is MySQL.

In MySQL Entity has check "IF Not Exists" on Entity property form.

If you want to check this option to all entities in model, you can write simple macro.

Something like that:

function Main(){
var App = System.GetInterface("Application");
var Model = App.ActiveModel;
var WS = App.ActiveWorkSpace;
var Log = System.CreateObject("Log");
if(Model==null) return;
if(WS==null) return;

var i, SelectObject;
for(i=0; i<This.Count;i++)
SelectObject = This.GetObject(i);
if (SelectObject.ObjectType==2501)
SelectObject = SelectObject.ParentBase;

SelectObject.IfNotExists = true;  



Owww, I’m sorry Daril…

So, my DB platform is PostgreSQL and TDM version is 5.4.

And I look for this option and I don’t find nothing.

So, you can help me? (I’ll try macro, but I prefer an “check” option! :-))


Hello Andrew,

“If Not Exist” is supported in Toad Data Modeler 5.4 for PG 9.3 and higher for Entities and Schemes. For Entity you can find it on General Tab(See pictures bellow).

In Toad Data Modeler version 6.0. and DB PG 9.5 are supported Materialized Views, Indexes and Sequences too.

Macro will help you only, when you want check a lot of objects at one moment.


Daril, I’m here again!!!

If I create a new model with PostgreSQL 9.3 or higher and this option is showed up…


Thank you!

Now, how can I change my model version to PostgreSQL 9.3?

You are welcome.

For change model version you need to use conversion wizard.

Open your model and go to Main Menu - Model - Convert Model - Run…

On first Page select Destination DB Platform. On second page can be useful uncheck option “Comment Out Database Specific Items…”. All others in wizard you can leave defaults.


Great! Thank you very much…

See you later… :slight_smile: