0

I'm using the dbatools powershell module to generate the schema of a SQLServer database.

The generated schema seems to be in alphabetical order, rather than in dependency order, so if there's a table A that has a constraint referencing table B then the generated schema cannot be executed. Similarly if there is a view VA referencing view VB.

I have a workaround for generating tables involving two export operations: one for the table definition, and one for the table constraints, using different scripting options. Kludgy, but it works. However I don't have a similar workaround for handling dependencies in views.

The dbatools powershell module delegates to SQLServer Mangement Objects (SMO), as does another tool mssql-scripter (implemented in python). I've experimented with mssql-scripter and it will generate schema in dependency order.

So I am assuming it must be theoretically possible for dbatools to generate schema in dependency order as well. Is this actually possible, and if so, how?

John Q Citizen
  • 321
  • 1
  • 6
  • 15

0 Answers0