Sql-server – SSMS: possible to script ‘file per object’ into categorised folders like in object explorer

sql-server-2012ssms

e.g. if you run the 'generate scripts' function (by right clicking on a db in object explorer) to script out an entire database, it creates all the files in one folder and annoyingly names them as [schema.objectname].[objecttype].sql

(at least if it were type.name it might be a little more readable)

Fine but I would rather mirror the object explorer convention of having Tables, Views, etc on a per folder basis containing only those object types and the file having exactly the same name as the object

Is there a simple way to achieve this?

Best Answer

You could import the database definition in SSDT using the "Schema Compare" tool.

Simply create an empty database project, right click and select "Schema compare". Select the project as target and the live database as source. Click "Compare" and then "Update": SSDT will script all objects and add them to your project.

SSDT by default creates a folder for each schema and in each folder creates separate folders for tables, stored procedures, views and so on.

SSDT tree