Toad World® Forums

Script to gonvert from Domains to Integer + Identity columns

Trying to adapt my data model to produce adequate SQL script for database creation. Since the MS SQL physical model is created from Universal model on a weekly basis, have to perform some repeatative actions

For instance, I have to manually edit about 20 entities and change their Primary Keys attributes to be DataType=Integer and Identity = true. Looking to write JScript to do it for me automatiucally, happy to hard code the entity names in the script.

This code does not seem to do it, I suspect the reason is that the Attribute has DOMAIN defined, its DataType is blank. So the script needs to somehow blank out the Domain and then set DataType

Hello Alexey,

I’ve just tried doing the same thing in MS SQL 2012 model and the Integer data type was assigned to all PK attributes that had previously defined Domain with no problems.

Try to check the following things:

  • Are you sure the script is applied to your MS SQL model? Note that this line (var Model = app.Models.GetObject(0);) uses the first Model displayed in Application View.
  • To get a Data Type by its name, you have to refer to its actual Name, not Caption. “Integer” is Caption while “Int” is Name (SQL Server Data Types in Reference Guide). So line number 11 should look like this:
    var DataType_int = Model.ModelDef.DataTypes.GetObjectByName(“Int”);
  • The Integer Data Type has no parametres, so you might want to get rid of line 33, just to make sure.
    Other than that, does the script actually do something after execution? Can you see any changes in your model?

Regads,

Lukas

Hi Lukas, yes this was it, had to change it from “Integer” to “Int” and it all worked. Noted on the Parameters. thanks for your help