# Reverse Engineer a database from the command line.

**URL:** <https://forums.toadworld.com/t/reverse-engineer-a-database-from-the-command-line/18270>\
**Category:** Toad Data Modeler\
**Created:** [May 23, 2013, 2:37am UTC](https://forums.toadworld.com/t/reverse-engineer-a-database-from-the-command-line/18270 "2013-05-23T02:37:34Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![daniel.edmonds\_968](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@daniel.edmonds\_968](https://forums.toadworld.com/u/daniel.edmonds_968)\
**Post date:** [May 23, 2013, 2:37am UTC](https://forums.toadworld.com/t/reverse-engineer-a-database-from-the-command-line/18270/1 "2013-05-23T02:37:34Z")

</div>

Hi,

I am attempting to take a database on a SQL server instance on my machine and, from the command line, have TDM create a new model, reverse engineer the DB into the new model, and save out the model file.

I have been able to launch toad with a blank model but I have not yet found a way to execute the appropriate scripts to preform the Reverse engineering.

Any help is appriciated.

Thank you,

Dan

---

<div class="post-metadata">

**Author:** ![Vaclav\_Frolik](https://sea1.discourse-cdn.com/quest/user_avatar/forums.toadworld.com/vaclav_frolik/32/12_2.png) [@Vaclav\_Frolik](https://forums.toadworld.com/u/Vaclav_Frolik)\
**Post date:** [May 24, 2013, 4:54pm UTC](https://forums.toadworld.com/t/reverse-engineer-a-database-from-the-command-line/18270/2 "2013-05-24T16:54:10Z")

</div>

Hi,

you can find an example in the Help file. See attached screenshot.

Regadrs,

Vaclav

 ![re-script.png](https://global.discourse-cdn.com/quest/original/2X/e/e20d96681cf1e472651e79638f70bc6d79e765d5.png)

---

<div class="post-metadata">

**Author:** ![daniel.edmonds\_968](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@daniel.edmonds\_968](https://forums.toadworld.com/u/daniel.edmonds_968)\
**Post date:** [June 10, 2013, 7:51am UTC](https://forums.toadworld.com/t/reverse-engineer-a-database-from-the-command-line/18270/3 "2013-06-10T07:51:46Z")

</div>

Thanks for pointing me in the right direction. I am having a little trouble with the example from the help file though. When I run the example, the script throws an error at the following line from the LoadPackagesByModelDefName, because MDef is null:

MDef.LoadPackages();

I’ve added some debugging statements and the GetObjectByName(AName) call is returning null when caled with AName = ‘Microsoft SQL Server 2008’

Am I using the wrong Model Definition name or do I have something else wron with my scripts?

Thanks again,

Dan

---

<div class="post-metadata">

**Author:** ![Vaclav\_Frolik](https://sea1.discourse-cdn.com/quest/user_avatar/forums.toadworld.com/vaclav_frolik/32/12_2.png) [@Vaclav\_Frolik](https://forums.toadworld.com/u/Vaclav_Frolik)\
**Post date:** [June 10, 2013, 8:29am UTC](https://forums.toadworld.com/t/reverse-engineer-a-database-from-the-command-line/18270/4 "2013-06-10T08:29:37Z")

</div>

Hi,

I have several questions for you:

1. What version of Toad Data Modeler do you use?

2. What is the name of your stored alias (TDM 4.x) or connection (TDM 5) ?

(Please provide screenshot, if possible.)

1. Did you install the software with all supported database platforms, please? (During installation you can choose database platforms. Ideally, install all items).

Thanks,

---

<div class="post-metadata">

**Author:** ![daniel.edmonds\_968](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@daniel.edmonds\_968](https://forums.toadworld.com/u/daniel.edmonds_968)\
**Post date:** [June 10, 2013, 12:18pm UTC](https://forums.toadworld.com/t/reverse-engineer-a-database-from-the-command-line/18270/5 "2013-06-10T12:18:15Z")

</div>

I have tried running this in Toad Data Modeler 4.3, as well as in version 5.0.5.31.

The Alias I created is called “DJE-alias1”. It connects to a DB on my local machine and is set to revese engineer the entire DB (Entities, Relationships, etc.)

![Toad_Alias1.jpeg](https://global.discourse-cdn.com/quest/original/2X/3/31a28f9ca409e664652666067c16448d69824752.jpeg)

I know that version 5.0.5 was installed with all the database platforms, and I believe that 4.3 was as well, though its been a while since I installed it.

The script that I am running from the scripting window in Toad 5.0.5 is attached. Please forgive the debuging message boxes.

Let me know if you need further detail of the Alias/Connection.

Thanks again,

Dan  
[ToadREScrpt.txt](https://global.discourse-cdn.com/quest/original/2X/6/6b80d5b395b0453e9c4be81b0855a3edd2195625.txt) (3 KB)

---

<div class="post-metadata">

**Author:** ![Vaclav\_Frolik](https://sea1.discourse-cdn.com/quest/user_avatar/forums.toadworld.com/vaclav_frolik/32/12_2.png) [@Vaclav\_Frolik](https://forums.toadworld.com/u/Vaclav_Frolik)\
**Post date:** [June 11, 2013, 8:03am UTC](https://forums.toadworld.com/t/reverse-engineer-a-database-from-the-command-line/18270/6 "2013-06-11T08:03:08Z")

</div>

Hi,

please use **MS SQL Server 2008** instead of **Microsoft SQL Server 2008**. We used to use MS abbreviation in past and then changed the caption from MS to Microsoft.

Wrong:  
var Model = RE(‘DJE-alias1’, App, ‘Microsoft SQL Server 2008’);  
Correct:  
var Model = RE(‘DJE-alias1’, App, ‘MS SQL Server 2008’);

To find out correct model def, do the following:

1. Create new model for selected targret database.
2. Enable Expert Mode in Settings.
3. Click Expert Mode | Scripting Window
4. Add your model to right side
5. Run the following script

function main(){  
Log.Information(Model.ModelDef.Name);  
}

![kom-modeldef.png](https://global.discourse-cdn.com/quest/original/2X/6/67c1d20c88e91c9c3a2ac4c8c9bec99448b0c9b8.png)

Result:

![kom-modeldef-1.png](https://global.discourse-cdn.com/quest/original/2X/a/abb06908c487008eb6198bd926f2e26ba64b77c4.png)

I hope it helps,

---

<div class="post-metadata">

**Author:** ![daniel.edmonds\_968](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@daniel.edmonds\_968](https://forums.toadworld.com/u/daniel.edmonds_968)\
**Post date:** [June 13, 2013, 5:49am UTC](https://forums.toadworld.com/t/reverse-engineer-a-database-from-the-command-line/18270/7 "2013-06-13T05:49:12Z")

</div>

Vaclav,

I figured that it was something like that. After correcting that the script is working correctly.

Thank you very much for your help.

Dan

---

<div class="post-metadata">

**Author:** ![Vaclav\_Frolik](https://sea1.discourse-cdn.com/quest/user_avatar/forums.toadworld.com/vaclav_frolik/32/12_2.png) [@Vaclav\_Frolik](https://forums.toadworld.com/u/Vaclav_Frolik)\
**Post date:** [June 17, 2013, 3:13am UTC](https://forums.toadworld.com/t/reverse-engineer-a-database-from-the-command-line/18270/8 "2013-06-17T03:13:04Z")

</div>

My pleasure 🙂
