You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[Primary Keys and Identity Columns](#primary-keys-and-identity-columns)
58
+
-[Primary Key Special Cases](#primary-key-special-cases)
59
+
-[Identity Columns](#identity-columns)
60
+
-[Columns with Default Values](#columns-with-default-values)
59
61
-[Trigger Binding](#trigger-binding)
60
62
-[Change Tracking](#change-tracking)
63
+
-[Internal State Tables](#internal-state-tables)
64
+
-[az_func.GlobalState](#az_funcglobalstate)
65
+
-[az_func.Leases_*](#az_funcleases_)
61
66
-[Trigger Samples](#trigger-samples)
62
67
-[Known Issues](#known-issues)
63
68
-[Telemetry](#telemetry)
@@ -826,20 +831,26 @@ public static IActionResult Run(
826
831
}
827
832
```
828
833
829
-
#### Primary Keys and Identity Columns
834
+
#### Primary Key Special Cases
830
835
831
836
Normally Output Bindings require two things :
832
837
833
838
1. The table being upserted to contains a Primary Key constraint (composed of one or more columns)
834
839
2. Each of those columns must be present in the POCO object used in the attribute
835
840
836
-
If either of these are falsethen an error will be thrown.
841
+
Normally ifeither of these are falsethen an error will be thrown. Below are the situations in which this is not the case:
837
842
838
-
This changes if one of the primary key columns is an identity column though. In that case there are two options based on how the functiondefines the output object:
843
+
##### Identity Columns
844
+
In the case where one of the primary key columns is an identity column, there are two options based on how the functiondefines the output object:
839
845
840
846
1. If the identity column isn't included in the output object then a straight insert is always performed with the other column values. See [AddProductWithIdentityColumn](./samples/samples-csharp/OutputBindingSamples/AddProductWithIdentityColumn.cs) for an example.
841
847
2. If the identity column is included (even if it's an optional nullable value) then a merge is performed similar to what happens when no identity column is present. This merge will either insert a new row or update an existing row based on the existence of a row that matches the primary keys (including the identity column). See [AddProductWithIdentityColumnIncluded](./samples/samples-csharp/OutputBindingSamples/AddProductWithIdentityColumnIncluded.cs) for an example.
842
848
849
+
##### Columns with Default Values
850
+
In the case where one of the primary key columns has a default value, there are also two options based on how the functiondefines the output object:
851
+
1. If the column with a default value is not included in the output object, then a straight insert is always performed with the other values. See [AddProductWithDefaultPK](./samples/samples-csharp/OutputBindingSamples/AddProductWithDefaultPK.cs) for an example.
852
+
2. If the column with a default value is included then a merge is performed similar to what happens when no default column is present. If there is a nullable column with a default value, then the provided column value in the output object will be upserted even if it is null.
853
+
843
854
### Trigger Binding
844
855
845
856
>**NOTE:** Trigger binding support is only available for C# functions at present.
>**NOTE:** The leases table contains all columns corresponding to the primary key from the user table and three additional columns named `_az_func_ChangeVersion`, `_az_func_AttemptCount` and `_az_func_LeaseExpirationTime`. If any of the primary key columns happen to have the same name, that will result in an error message listing any conflicts. In this case, the listed primary key columns must be renamed for the trigger to work.
871
882
883
+
#### Internal State Tables
884
+
885
+
The trigger functionality creates several tables to use fortracking the current state of the trigger. This allows state to be persisted across sessions and for multiple instances of a trigger binding to executein parallel (for scaling purposes).
886
+
887
+
In addition, a schema named `az_func` will be created that the tables will belong to.
888
+
889
+
The login the trigger is configured to use must be given permissions to create these tables and schema. If not, then an error will be thrown and the trigger will fail to run.
890
+
891
+
If the tables are deleted or modified, then unexpected behavior may occur. To reset the state of the triggers, first stop all currently running functions with trigger bindings and then either truncate or delete the tables. The next time a functionwith a trigger binding is started, it will recreate the tables as necessary.
892
+
893
+
##### az_func.GlobalState
894
+
895
+
This table stores information about each functionbeing executed, what table that functionis watching and what the [last sync state](https://learn.microsoft.com/sql/relational-databases/track-changes/work-with-change-tracking-sql-server) that has been processed.
896
+
897
+
##### az_func.Leases_*
898
+
899
+
A `Leases_*` table is created forevery unique instance of a function and table. The full name will bein the format `Leases_<FunctionId>_<TableId>` where `<FunctionId>` is generated from the functionID and `<TableId>` is the object ID of the table being tracked. Such as `Leases_7d12c06c6ddff24c_1845581613`.
900
+
901
+
This table is used to ensure that all changes are processed and that no change is processed more than once. This table consists of two groups of columns:
902
+
903
+
* A column foreach columnin the primary key of the target table - used to identify the row that it maps to in the target table
904
+
* A couple columns for tracking the state of each row. These are:
905
+
*`_az_func_ChangeVersion`for the change version of the row currently being processed
906
+
*`_az_func_AttemptCount`for tracking the number of times that a change has attempted to be processed to avoid getting stuck trying to process a change it's unable to handle
907
+
* `_az_func_LeaseExpirationTime` for tracking when the lease on this row for a particular instance is set to expire. This ensures that if an instance exits unexpectedly another instance will be able to pick up and process any changes it had leases for after the expiration time has passed.
908
+
909
+
A row is created for every row in the target table that is modified. These are then cleaned up after the changes are processed for a set of changes corresponding to a change tracking sync version.
910
+
872
911
#### Trigger Samples
873
912
The trigger binding takes two [arguments](https://github.com/Azure/azure-functions-sql-extension/blob/main/src/TriggerBinding/SqlTriggerAttribute.cs)
0 commit comments