sethreno / schemazen

Script and create SQL Server objects quickly
MIT License
332 stars 140 forks source link

Aggregate Functions not Scripted #214

Open VivianDZ opened 1 year ago

VivianDZ commented 1 year ago

Hi - I just noticed Aggregate functions are not being scripted when I run the script command. Is there any specific way to do this?

keith-hall commented 11 months ago

The first thing to check, is does your aggregate function appear in the output of https://github.com/sethreno/schemazen/blob/master/Library/Models/Database.cs#L553-L571?

VivianDZ commented 11 months ago

Hi - It doesn't show in the Query above. It does exist in the sys.objects table though (but not in sys.sql_modules).

image

One thing to add is both are CLR Aggregate functions.

image

keith-hall commented 11 months ago

Probably it will make sense for schemazen to have a separate model for aggregates. The syntax for reference is https://learn.microsoft.com/en-us/sql/t-sql/statements/create-aggregate-transact-sql?view=sql-server-ver16#syntax. There's an example C# project linked to at the bottom of the page which can be used for easy testing. Schemazen already supports CLR assemblies, so hopefully not too hard to add... https://github.com/sethreno/schemazen/blob/master/Library/Models/Assembly.cs