Posts

Showing posts from September, 2020

SQL Server: How to get the Last Inserted Identity value. What is the fastest way?

Image
Hello friends, Very often after inserting a row in a table it is necessary to know what is the id of the row just inserted. We have various methods but what is the fastest? Today we take a watch to this question! Enjoy the reading!   As usually for maximum clarity we will proceed with an example using our standard table. It has an identity column called ID  The classic way!   SELECT MAX ( ID ) FROM ORDTES   (1 riga interessata) Tabella 'OrdTes'. Conteggio analisi 1, letture logiche 2, letture fisiche 0, letture read-ahead 0, letture logiche LOB 0, letture fisiche LOB 0, letture read-ahead LOB 0.   (1 riga interessata)     SELECT TOP 1 ID FROM ORDTES ORDER BY ID DESC         (1 riga interessata) Tabella 'OrdTes'. Conteggio analisi 1, letture logiche 2, letture fisiche 0, letture read-ahead 0, letture logiche LOB 0, letture fisiche LOB 0, letture read-ahead LOB 0.       We can note that with these f...

SQL Server, MrbMiner the new malware that infects SQL Server!

Image
Hello friends, Today we will talk about security because it is a recent new that a new malware is  trying to infect SQL Server. Its name is MrbMiner . The goal is always the same: installing a Cryptominer in order to use the power of the server to mine cryptocurrency! We have already talked about security here https://sqlserverperformace.blogspot.com/2020/03/sql-server-corona-virus-smartworking.html https://sqlserverperformace.blogspot.com/2020/04/sql-server-botnet-and-cryptomining-is.html Enyoj the reading!   The new malware that infects SQL Server has a name, its name MrbMiner. Its goal is to install on your server a cryptominer. According to the chinese tech giant Tencent over thousands SQL Server databases have been infected!   How does it work? This malware spreads exclusively by scanning the internet for SQL servers and performing a brute force attack by repeatedly trying the administrator account with weak passwords. If the MrbMiner malware gains access to th...

SQL Server // Do you want to lean how to pivot data in 5 minute?

Image
Hi friends, What do you think about learning more about pivoting ? It is usually not considered a simple topic but it really is! Go! So, what is the pivoting operation?   The pivoting operation consists in transforming the data coming from rows of a table into data grouped on several columns .   We can consider the pivoting operation as an operation consisting of these three phases carried out in order: 1. Grouping (we want to have only one row for each distinct element on the rows. It is equivalent to a GROUP BY operation) 2. Spreading (we want to have n columns in which to box the values ​​that we will then aggregate. It is equivalent to a CASE) 3. Aggregating (we aggregate the values ​​on the columns for example with the SUM function)     For example, we could pivot data in this way: SELECT   SUM ( CASE WHEN BR . CODE = 'NIKE' THEN   CR . QTA END ) AS [QTY_FOR_BRAND_WITH_CODE_NIKE] ,   SUM ( CASE WHEN BR . CODE = 'SNEAKERS' THEN CR ...