Posts

Showing posts with the label UDF

SQL Server, how to use a user function as default for a column

Image
Hi guys, Welcome this post mates. Today a super light post only to show how to use a function as a default value for a column of a SQL server Table. Simply and easy as usual! Enjoy the reading!   How to use a function as default for a column   A columns of a table in SQL Server can have a default value. Simply, if I insert a row using the insert statement and I do not specify the name of a field, in that case the default value will be used for that field. Let's see how a default is defined on a field. To add a default value you simply add the default and a value after the type definition of the field. CREATE TABLE ORDTES (ID INT IDENTITY (1,1), CODE VARCHAR (20), TOTAL_VALUE FLOAT DEFAULT 0 ) Obviously we can specify any value consistent with the type of the field. Now, if you do not specift the field total_value in the insert statement: INSERT INTO ORDTES (CODE) VALUES ( 'AAA' ) The default value will be used: Sometimes, however, our default is not a fixed value. ...

SQL Server 2019 CU11 is out! ....and again on Scalar UDF Inlining

Image
Hi Guys, The SQL Server CU 11 is out.  Looking to the Microsoft changelog there aren't great imprevements from point of view of the performance, but from what i can see there is another update on the "Scalar UDF Inlining" saga! We talked about Scalar UDF inlining here: SQL Server, boost your UDFs! Yes i really think that UDF inlining (debut with SQL Server 2019 in order to increase performance) will became an important technology but what is happened unfortunately is a little different. Due to errors, at each CU Microsoft restricted the action and the functionality of the Inlining.. For example in the CU2 inlining is blocked if the UDF references built-in views (for example . OBJECT_ID) or when aggregate functions are passed as parameters to a scalar UDF. Again if the UDF references certain intrinsic functions (for example @@ROWCOUNT. Updating to the CU4 inlining is blocked if the UDF uses XML methods or contains a SELECT with ORDER BY without a "TOP 1" and eve...

SQL Server 2019 e le inline scalar function

Image
Ciao a tutti, Voglio ringraziare per le numerose visite a questo blog. Grazie inoltre per le domande che mi sono pervenute, cercherò di dare un risposta a tutti quelli che mi hanno scritto. Promesso! Anche oggi volevo mostrarvi una miglioria ed un altro motivo in più per upgradare a SQL Server 2019. Questo volta parliamo di User Defined function conosciute anche con l'acronimo di UDF . Diciamo subito che in SQL Server possiamo avere tipi diversi di UDF: Le funzioni scalari ovvero quello che ritornano un solo valore Le funzioni multi-statement table valued  dette TVF che ritornano più valori Le funzioni inline table valued che sono ottimizzate per le prestazioni. Oggi parleremo solo delle funzioni scalari . Una esempio può essere la seguente funzione scalare: CREATE OR ALTER FUNCTION F_GET_PREZZO (@ARTID INTEGER) RETURNS FLOAT AS BEGIN DECLARE @Prezzo FLOAT SELECT @Prezzo = PREZZO FROM LISTINO WHERE ARTID=@ARTID; RETURN (@Prezzo) END ; Dall...