Author: way0utwest

  • A New Word: Nighthawk

    nighthawk – n. a recurring thought that only seems to strike you late at night – an overdue task, a nagging guilt, a looming future – which you sometimes manage to forget for weeks, only to feel it land on your shoulder once again, quietly building a nest.

    I am typically not a night person. I tend to fall asleep early (avoiding late night movies or events) and I can often sleep through the night. I tend to awaken a bit more as I age, but in general I’m not plagued by any sort of insomnia and am not awake at night.

    Not often.

    However, I often to have various commitments coming, lots of travel, and a chaotic life. Often I find myself reviewing a mental to-do list, worrying that I’ve forgotten something or I didn’t complete a task. I do have a physical list, but often there are so many repeating items that I don’t always write them down.

    This usually comes before I speak at some event, and I find myself waking and worrying at night that I didn’t get something done before my presentation the next day.

    Interestingly, I almost never think about forgetting to schedule a newsletter. I do that sometimes, but rarely.

    From the Dictionary of Obscure Sorrows

  • SQL Prompt Tips–Using $surroundtext$ in a Snippet

    A user on the SQL Community Slack was asking about what the $surroundtext$ variable. This post looks at how this can be used in snippets.

    This is part of a series of posts on SQL Prompt. You can see all my posts on SQL Prompt under that tag.

    A Scenario

    I find that I want to convert some inline SQL to a stored procedure. We have a lot of code in an application that looks like this:

    SELECT 
         SUM(sod.OrderQty) OVER(ORDER BY sod.SalesOrderID, sod.ProductID) AS Total
      FROM Sales.SalesOrderDetail AS sod
      WHERE sod.ProductID = <somevalue>

    The application replaces <somevalue> with an actual value and runs this code. This potentially is a SQL Injection vector, but this also isn’t easily tuned on the server, and can get copied and pasted into different places in the code. It would be better to have this as a stored procedure.

    Make the Conversion Easy

    To make this a stored procedure, I would want this query to look like this:

    CREATE PROCEDURE dbo.GetGroupedSales
         @Id INT
    AS
    BEGIN
    SELECT 
         SUM(sod.OrderQty) OVER(ORDER BY sod.SalesOrderID, sod.ProductID) AS Total
      FROM Sales.SalesOrderDetail AS sod
      WHERE sod.ProductID = @id
    
    END

    I can create a snippet that looks like the skeleton of a stored procedure with this code:

    create procedure $procname$
    $param1$ $paramdt$
    as
    begin
    $SELECTEDTEXT$
    end
    go

    I’ve got a screenshot of this below, showing some default values for the various parameters. This makes it easy for me to build a proc. However, there is one variable that isn’t in the list: $SELECTEDTEXT$.

    This variable will take any text that is selected in SSMS (or VS) and put it inside of the snippet in that location specified.  That will help us wrap our query with the other code in the snippet.

    Here is my snippet:

    2023-11-10 14_17_05-SQL Prompt - Edit Snippet

    Using the Snippet

    Let’s see this in action. In SSMS, I have highlighted my query.Notice the little Prompt popup near the cursor.

    2023-11-10 14_23_22-SQLQuery2.sql - ARISTOTLE_SQL2022.AdventureWorks2017 (ARISTOTLE_Steve (71))_ - M

    When I see this, I can hit the CTRL key and I’ll get a drop down list. I will type “mp” which is my snippet code.

    2023-11-10 14_23_29-SQLQuery2.sql - ARISTOTLE_SQL2022.AdventureWorks2017 (ARISTOTLE_Steve (71))_ - M

    This finds my snippet. I can hit Tab and my snippet is inserted, with my default variable values and also the text I selected in the place where $SELECTEDTEXT$ was in the snippet.

    2023-11-10 14_23_58-SQLQuery2.sql - ARISTOTLE_SQL2022.AdventureWorks2017 (ARISTOTLE_Steve (71))_ - M

    Now like any other snippet, I can tab between the variables and change them. When I’m done, I hit Enter and I have my code.

    Now I just need to save this in version control and deploy it to my production system.

    If you haven’t tried SQL Prompt, download the eval and give it a try. I think you’ll find this is one of the best tools to increase your productivity writing SQL.

    Video Walkthrough

    I made a video of using $surroundtext$ that you can watch. All my SQL Prompt tips are in this playlist.

     

  • A Lack of Privacy in Smart Cars

    I own a Tesla, and I love having a bunch of data about my usage of the car. I can see how much I’ve charged it, what it costs to power, where I drive, aggregates of my monthly usage, and more. It’s especially cool when my wife is coming to pick me up, and I can see where the car is, so I know when to go outside if the weather isn’t great. I also like the ability to cool or heat the car in advance of going outside in extreme temperatures.

    However, all that data also means there are potential issues with privacy and certainly security. I am well aware that location and other data are being captured by Tesla as I use the car. However, it’s not just Tesla. Lots of modern cars are collecting lots of data. Mozilla had a report on data privacy in cars, and all the manufacturers failed their data privacy test. There’s also a summary at Engadget of the results.

    Reading through the report, it seems that many of the manufacturers of cars are covering themselves from liability. Cars are sold and used in many jurisdictions and often there can be a wide variety of regulations about data, even inside of a single country. It seems that the policies are often written just in case something happens and they collect data from your use of the car (or they record you using the car).

    A point I hadn’t considered in the article dealt with the deletion of data when a car is sold. That could get tricky as not only is your usage data in the car, some data might potentially be in a manufacturer’s database. Or it might be stored in devices at a service center. Who knows what gets stored and copied in modern cars as they are serviced. Will we potentially have issues with mechanics or other workers stealing and selling data from entertainment or other information systems in cars? The possibilities make my head hurt in this modern world where everything can, and often does, collect data.

    I don’t know what data is stored inside modern vehicles or other systems. In some sense, I think that companies ought to disclose what they collect, and include examples of what this data looks like. Even when I read policies, like this one from Microsoft, I’m not completely sure if I know what data they may be collecting.

    The world of data privacy is complex, and as I’ve written before, I’m not even sure exactly how I would like my data handled. I think the GDPR is a good start, but I hope that we continue to evolve protections that ensure humans have more control over their data than the companies that collect it.

    Steve Jones

    Listen to the podcast at Libsyn, Spotify, or iTunes.

  • Data Security and AI

    I ran across an article on the best AI meeting assistants, which can help you with note-taking and summarization tasks. Most of these cost money, but there was something that struck me about these tools.

    They aren’t allowed for a lot of my meetings.

    At Redgate, I’m not sure if these are allowed. Our policy is to seek permission before using a tool, so I’ve sent a query off for more information. In many of my customer meetings or in Microsoft meetings, I’ve been told these tools aren’t allowed as there isn’t sufficient data security to allow their usage.

    I think a lot of people are concerned about their data when these AI LLMs (large language models) are involved and if their data is being used to train future models. If it is, then that could be a security problem. Already many people and organizations are upset about their data sets being used for training without their knowledge. Not everyone agrees.

    I don’t quite know how I feel about this issue, but I do think there ought to be guidelines and discussions about how data is used, and where data is stored (or where it transits a network). Certainly, organizations might need to set this in place to ensure their employees aren’t exposing confidential or internal data in ways that could increase their risk of a breach. After all, without any guidelines or rules, you may have no recourse if employees just use tools and data escapes your network.

    At Redgate, we’ve begun experimenting with SQL Prompt and AI. As of now, we’ve had quite a few queries about how customer data is being used. Our EAP EULA notes that schema information will leave your network, but not data in rows. That might be a problem or might not, but it’s important to disclose that, which we’ve done.

    I’d like to think that as hardware power increases and models become more mature, we’ll stop having to send data for many AI-related tasks away from a device that might perform a task. At some point, I hope your mobile phone or laptop can process the AI model without a network connection, which would be helpful for data security.

    AI is here to stay, and we have to learn how to work with it, and where it works well. It feels a little like we haven’t really answered many of these questions as an industry or inside our organizations. That’s something that needs to change and quickly as the number of places AI is being used continues to rapidly increase.

    Steve Jones

    Listen to the podcast at Libsyn, Spotify, or iTunes.