Posts

Showing posts from July, 2020

SQL Server, how to detect if the values of a column have changed

Image
Hi Guys, Welcome back! Today we have a little insight into the world of triggers . We will see in which ways to detect if the values ​​of a column have changed Ready? Go! The UPDATE function In a trigger, the UPDATE (FIELD) function is the fastest way to check whether the value of the <FIELD> field has changed. It is faster because it only parses the T-SQL command to be executed even if the field value is not actually changed. Example: UPDATE TABELLA SET FIELD = FIELD always return TRUE Reading the tables INSERTED and DELETED Alternatively, to check if the value of a field has been changed, you can query the two tables INSERTED and DELETED by putting them in JOIN: IF EXISTS( SELECT I.ID FROM INSERTED I JOIN DELETED D ON I.ID = D.ID WHERE I.FIELD <> D.FIELD) BEGIN END That's all for Today! Luca You may also be interested in: SQL Server: Transazioni, Lock e Deadlock. Un po di teor

How SQL Server fills mdfs and ldf with data: Proportional fill and Round robin

Image
Hi Guys, Welcome back! Last time we talked about the TempDB database Here . We ran some benchmarks to inspect performances variation adding one or more mdf files to the TempDB. So we have seen in which order mdf and ldf files are filled . You surely noted that we didn't say anything about how they are filled . Well we will do it now! So my friends... Enjoy reading this post i wrote (from my mobile office overlooking the Alps!!!) Simple case, one mdf file For this first simple test we create a new database named TestPF. Our dabatase will have a single mdf file. DROP DATABASE [TestPF] CREATE DATABASE [TestPF] ON ( NAME = N'PF' , FILENAME = N'E:\PF.mdf' , SIZE = 131072KB, FILEGROWTH = 131072KB) LOG ON ( NAME = N'PF_log' , FILENAME = N'E:\PF_log.ldf' , SIZE = 131072KB, FILEGROWTH = 131072KB) GO ALTER DATABASE [TestPF] SET RECOVERY SIMPLE GO Now we define a Query that return how much our mdf and ldf fil