Tag: AI

  • AI Helping with an API

    Can an AI help me with some database API work? Let’s see.

    This is part of a series of experiments with AI systems.

    The Scenario

    One of the things that helped me support a number of development teams with their database work was having code generate code. I had a piece of code that could read the system tables in SQL Server and produce insert, update, and delete procedures.

    I wondered if an AI could do this easily.

    Using Copilot

    I decided to try this first in the Edge Copilot window. I wrote this prompt:Create the T-sQL code for insert, update, and delete procedures for these tables:

    I then pasted in the code for 5 tables from Northwind, such as this one:

    CREATE TABLE "Employees" ( "EmployeeID" "int" IDENTITY (1, 1) NOT NULL , "LastName" nvarchar (20) NOT NULL , "FirstName" nvarchar (10) NOT NULL , "Title" nvarchar (30) NULL , "TitleOfCourtesy" nvarchar (25) NULL , "BirthDate" "datetime" NULL , "HireDate" "datetime" NULL , "Address" nvarchar (60) NULL , "City" nvarchar (15) NULL , "Region" nvarchar (15) NULL , "PostalCode" nvarchar (10) NULL , "Country" nvarchar (15) NULL , "HomePhone" nvarchar (24) NULL , "Extension" nvarchar (4) NULL , "Photo" "image" NULL , "Notes" "ntext" NULL , "ReportsTo" "int" NULL , "PhotoPath" nvarchar (255) NULL , CONSTRAINT "PK_Employees" PRIMARY KEY CLUSTERED ( "EmployeeID" ), CONSTRAINT "FK_Employees_Employees" FOREIGN KEY ( "ReportsTo" ) REFERENCES "dbo"."Employees" ( "EmployeeID" ), CONSTRAINT "CK_Birthdate" CHECK (BirthDate < getdate()) ) GO CREATE INDEX "LastName" ON "dbo"."Employees"("LastName") GO CREATE INDEX "PostalCode" ON "dbo"."Employees"("PostalCode") GO

    I got this result:

    -- Insert Procedure
    CREATE PROCEDURE InsertEmployee
         @LastName nvarchar(20),
         @FirstName nvarchar(10),
         @Title nvarchar(30),
         @TitleOfCourtesy nvarchar(25),
         @BirthDate datetime,
         @HireDate datetime,
         @Address nvarchar(60),
         @City nvarchar(15),
         @Region nvarchar(15),
         @PostalCode nvarchar(10),
         @Country nvarchar(15),
         @HomePhone nvarchar(24),
         @Extension nvarchar(4),
         @Photo image,
         @Notes ntext,
         @ReportsTo int,
         @PhotoPath nvarchar(255)
    AS
    BEGIN
         INSERT INTO Employees (LastName, FirstName, Title, TitleOfCourtesy, BirthDate, HireDate, Address, City, Region, PostalCode, Country, HomePhone, Extension, Photo, Notes, ReportsTo, PhotoPath)
         VALUES (@LastName, @FirstName, @Title, @TitleOfCourtesy, @BirthDate, @HireDate, @Address, @City, @Region, @PostalCode, @Country, @HomePhone, @Extension, @Photo, @Notes, @ReportsTo, @PhotoPath)
    END
    GO
    -- Update Procedure
    CREATE PROCEDURE UpdateEmployee
         @EmployeeID int,
         @LastName nvarchar(20),
         @FirstName nvarchar(10),
         @Title nvarchar(30),
         @TitleOfCourtesy nvarchar(25),
         @BirthDate datetime,
         @HireDate datetime,
         @Address nvarchar(60),
         @City nvarchar(15),
         @Region nvarchar(15),
         @PostalCode nvarchar(10),
         @Country nvarchar(15),
         @HomePhone nvarchar(24),
         @Extension nvarchar(4),
         @Photo image,
         @Notes ntext,
         @ReportsTo int,
         @PhotoPath nvarchar(255)
    AS
    BEGIN
         UPDATE Employees
         SET LastName = @LastName, FirstName = @FirstName, Title = @Title, TitleOfCourtesy = @TitleOfCourtesy, BirthDate = @BirthDate, HireDate = @HireDate, Address = @Address, City = @City, Region = @Region, PostalCode = @PostalCode, Country = @Country, HomePhone = @HomePhone, Extension = @Extension, Photo = @Photo, Notes = @Notes, ReportsTo = @ReportsTo, PhotoPath = @PhotoPath
         WHERE EmployeeID = @EmployeeID
    END
    GO
    
    
    
    
    -- Delete Procedure
    CREATE PROCEDURE DeleteEmployee
         @EmployeeID int
    AS
    BEGIN
         DELETE FROM Employees WHERE EmployeeID = @EmployeeID
    END
    GO
    
    

    Here’s an image of what I saw:

    2024-11_0126

    You might ask if this is better than what I’d write. I wondered myself, so I asked it to change the update procedure slightly. Here’s the prompt and result:

    2024-11_0127

    -- Update Procedure
    CREATE PROCEDURE UpdateEmployee
         @EmployeeID int,
         @LastName nvarchar(20) = NULL,
         @FirstName nvarchar(10) = NULL,
         @Title nvarchar(30) = NULL,
         @TitleOfCourtesy nvarchar(25) = NULL,
         @BirthDate datetime = NULL,
         @HireDate datetime = NULL,
         @Address nvarchar(60) = NULL,
         @City nvarchar(15) = NULL,
         @Region nvarchar(15) = NULL,
         @PostalCode nvarchar(10) = NULL,
         @Country nvarchar(15) = NULL,
         @HomePhone nvarchar(24) = NULL,
         @Extension nvarchar(4) = NULL,
         @Photo image = NULL,
         @Notes ntext = NULL,
         @ReportsTo int = NULL,
         @PhotoPath nvarchar(255) = NULL
    AS
    BEGIN
         UPDATE Employees
         SET LastName = COALESCE(@LastName, LastName),
             FirstName = COALESCE(@FirstName, FirstName),
             Title = COALESCE(@Title, Title),
             TitleOfCourtesy = COALESCE(@TitleOfCourtesy, TitleOfCourtesy),
             BirthDate = COALESCE(@BirthDate, BirthDate),
             HireDate = COALESCE(@HireDate, HireDate),
             Address = COALESCE(@Address, Address),
             City = COALESCE(@City, City),
             Region = COALESCE(@Region, Region),
             PostalCode = COALESCE(@PostalCode, PostalCode),
             Country = COALESCE(@Country, Country),
             HomePhone = COALESCE(@HomePhone, HomePhone),
             Extension = COALESCE(@Extension, Extension),
             Photo = COALESCE(@Photo, Photo),
             Notes = COALESCE(@Notes, Notes),
             ReportsTo = COALESCE(@ReportsTo, ReportsTo),
             PhotoPath = COALESCE(@PhotoPath, PhotoPath)
         WHERE EmployeeID = @EmployeeID
    END
    GO

    That’s interesting. If I pass in nulls for everything, I get an update in place. Not quite what I’d do, as I’d check if the param was null and not include it in an update, which could reduce logging, but this is likely just as efficient.

    Easy code to write for sure, and I could likely put together a bit of code to do this for me, but it’s nice that I can quickly ask an AI to do this. I think this is the type of thing that might be easier for developers to do, and maybe more likely. They get to play with AI and feel more productive. They can even alter a table and “re-ask” for new procedures where they can interact with the table.

    What’s more, the INSERT procedures have the explicit column lists, so this means I could rev the underlying table without breaking this code. It’s a good coding practice, but far too many people would just embed a this in their code:

    insert Employee values ‘Jones’, ‘Steve’, ‘Editor’, …

    A quick thing, but Copilot seemed to work well here.

  • PASS Data Community Summit 2024 Day 3 Keynote

    It’s been an amazing week here, as well as a long week. I’m tired, as are many others. The blogging table is a little bare this am, but I do understand. Louis Davidson invited me to the Simple Talk breakfast and it was a struggle to get up, pack, and make it to the event. I was a little late, but I got there in time to catch Louis’ remarks.

    20241108_082924

    This morning the keynote opens with Ben Weissman, who gave last year’s community keynote with Melody Zacharias.

    I love that we have the previous year’s speaker introduce the next one. Ben tells us that he started growing his career here at the Summit, as have many others. Ben tries to help others grow and expand their careers, and I hope a few people get inspired to start blogging, speaking, and more. Most of us you see on stage started just like those of you in the audience.

    This is live-ish blogging, so apologies for typos. I’ve tried to italicize my thoughts.

    Privilege

    We are privileged to be here. Our companies invested in us, or we can afford it. We get the time to come. We get to interact with others in our industry, get some swag, enjoy the

    Ben thanks the DEIB committee, which does a lot of small things. The code of conduct, the non-alcoholic bar, gender neutral bathrooms and more. These items might not affect you, but they make the event better for others.

    There is also a New Stars track for new people who have never spoken. You can submit to this, which is a separate process from the main submissions. Ben runs New Stars of Data (with William Durkin) and he can help. He’s more than willing to help.

    He also thanks a lot of people in the community that helped him. I feel the same way, in that we work hard, but success comes with help from others.

    You might think others are doing much better than you. There certainly are those people, but there are also many more doing less well than you.

    Appreciate what you have and acknowledge your privilege. You don’t need to apologize for it, but don’t pretend it doesn’t exist.

    Generating Innovation

    Ginger comes out, asking about the media we used to watch. Gilligan’s Island for her, on a TV. Today, kids watch YouTube, Tiktok, etc., and on their phones. They watch things like this.

    2024-11_line0006

    Cable TV is going away, and a survey of younger people showed most thought this was going to happen.

    20241108_084426

    Today everyone talks about AI and that we might lose our jobs. Ginger thinks this is hype.

    But it is an important tool. Learn, innovate, be better.

    Netflix is the first example. They worked by mail, competing with Blockbuster. They took a chance on streaming, which I remember. Wondering if we could actually get enough bandwidth. Today Netflix dominated over others.

    First is not the most successful. Lots of tech was first, but hasn’t survived. Visicalc, Lotus 1-2-3 were first and everywhere, but they didn’t survive. Excel took over. They had a button to emulate Lotus, so that users could move. Excel innovated and won.

    You need to innovate and change to survive. Ben is the example. He was (is?) a VB6 developer. However, if he stuck there, he might not be on stage, in the community, owning a company, and more. He changed and innovated.

    That can be each of us. Ginger reminds us that other people help us grow, learn, get inspired, and do more. People are the reason companies innovate.

    Innovation requires curiosity, brave, and willing to fail. You have to take risks. If you start something new, you won’t be great, but you can learn and finds ways to innovate.

    SpaceX and musk shown. Why do some companies succeed in new ways? I think this is a great example, as this company changed the way rockets and space exploration works.

    Who remembers and awful job. Ginger’s gave her headaches every Sunday, in anticipation of going back to work Monday. She didn’t plan this, but found herself in the situation.

    We need to prepare for the future, be ready in advance. Explore your world, look at what’s important, what are others doing?

    I hear this a lot from people, but the devil is in the details, and I know that lots of people question what to do. I both agree with Ginger’s advice, and I don’t. A few years ago we were told we needed R. Lots of people, including me, spent time on R as it was added to SQL Server, ML was a big deal, and we saw others learning this.

    Today R isn’t something I see widely used. Python has taken over more, Databricks and Spark and other tech is being used more often, but will that continue? I don’t know.

    Ginger worked at a company she thought was good, but started to see people leaving because they weren’t valued and didn’t work on interesting things. Money wasn’t the reason, and I agree. I think back to Drive, which talks about Autonomy, Mastery, and Purpose. Monday matters, but those things bring more satisfaction (if the money is good enough).

    Ginger overworked herself at a job. She got sick, but thought she’d have done a good job. She asked why she was asked to do all the work in December.

    “did you get it done?”

    “She said yes, and the response was, “I guess I picked the right person for the job.”

    The boss felt he’d done a good job, but Ginger didn’t feel that way. She felt like she’d been abused and taken advantage of in the situation. She wasn’t valued. The same feeling of her friends.

    She left and that company failed. That company didn’t value employees. That could be us? Do we value our situations, our friends, our knowledge?

    I think that’s a decent analogy, because there are companies (that I know) and people who do continue to survive and do well even though they aren’t liked, or good, or anything. Sometimes they take advantage of the market (companies) or their situation/power (people) and others don’t like them but feel trapped. Or they constantly find new people that don’t know how toxic or unsatisfying it is around those people.

    I don’t know if those are exceptions, or if they’re the minority or even majority. I do know that those aren’t places I want to work, or people I want to spend time around. I also know there are lots of other opportunities.

    Ginger mentions pay, and that more pay doesn’t necessarily ensure you’ll enjoy the situation. I’ve learned that the hard way as well. I have often found that more pay isn’t better. I can get better pay and a better situation, but I can also accept slightly less pay and enjoy the situation more. Have I done this? Yes. I made $75k at one point and took a $68k job. It was totally work it.

    The Mississippi Miracle. After being ranked #50 in a 4th grade reading assessment (9-10yr olds), the US state found a new way to teach kids to read. They trained teachers, made an investment that was small, and they improved dramatically.

    I think this is a great example. A little investment in your career is what I ask. Not a part-time job investment, but a 1, 2, 4 hour a week investment. It can make a difference. I was talking to someone about blogging last night. I said you could write 1 small post a week. In a year, that’s 50 posts. That’s a lot of stuff to showcase about your career, a lot of practice to learn better communication skills, and a lot to learn about what you know or do. If you want a better year in a year or two, start now.

    Netflix had a recession, they laid off 30% of the company. They realized they had good people and had to let those people do work. They trusted them (autonomy), they asked them to work on things that helped the company (purpose), and gave them opportunities to showcase their knowledge and improve (mastery).

    If you haven’t read about things the Netflix engineers do, or seen talks from them, they have done amazing things. They innovate in tech. Their engineering blog is amazing, even though I don’t know most of the tech behind what they do. I’m frequently lost, but I also recognize these are very smart people getting things done.

    I’m not saying Netflix is amazing culturally, but they are impressive.

    Ginger notes she looked for opportunities and tried to find ways to get into a new department. They kept promising things, but never moved her, so she quit.

    Glassdoor, mentioning this is a good resource. One review, best thing is the food trucks outside because everything inside is garbage.

    Take Glassdoor with a grain of salt. There are always people who just gripe or are unhappy. My view is toss away 5% of the top and bottom reviews.

    It can be helpful in determining if you can trust the company and management.

    Training provides opportunity. If your employer provides them, great. If not, you need to do your own training. You want to create your own safety net for the future.

    I believe in this. In places resistant to investing, I usually do some, show what I’ve done and then ask for matching. That has worked in multiple situations.

    Ginger notes that she talked to someone who got upgraded on a flight. They talked to a manager/owner next to them. The owner noted their employees were in the back and that’s a bad message.

    Yes and no. Costs are a factor, and sometimes people get benefits because they travel a lot. I get upgraded and don’t apologize. I’ve had bosses that were in first while I was in coach because they had status and I didn’t. Or they spent money on an upgrade. I’ve also had bosses that use the same policy as employees. We do that at Redgate.

    Don’t get too black and white with specifics, look for trends. Fair and equal doesn’t always mean the same for everyone.

    What’s important to you? Talk to people to find out. Learn what matters to you. If you don’t like your situation, find a better situation and quit.

    It costs 150% of a person’s salary to replace them. Is that crazy? Think about all the time, all the effort, the work not being done, the training time. Ginger thinks this isn’t necessarily a bad number.

    Lat year a company gook their employees out to dinner at an expensive dinner at PASS. They then told the people because the food is expensive, they’d order family style and share. Made the employees think that management didn’t value them.

    I’d agree here. Don’t cheap out if you make the decision to spend money.

    Example of an employee that lives in S Dakota. The employee sends this person to a conference in Florida in December as a perk. He asks, chooses a time and place that suits him, and is happy. He’s still at the company.

    20241108_092520

    Good employees get more opportunities and more perks. It’s fair because they often provide more value to the company. Keep that in mind when you ask for something and it gets declined. Some managers are just jerks, but I often question myself and sometimes realize that I might not deserve something.

    Prompt Engineering

    Everyone needs to learn how to do this. Take a course, and it doesn’t take 6 hours. Do these things:

    • be specific about how much text in the answer (give me 5 things)
    • pick the persona you want to answer the questions (act as a travel agent)
    • ask for clarification from the previous question (give me more)
    • ask AI how to ask AI a question (how could I have asked this better)

    You can learn more by doing this. With generative AI, which generates responses, but also generates hallucinations. Because of this, ask for links and check them.

    Ginger showed her Dad how to follow this method with AI and he was surprised by his success.

    Go out and do good prompt engineering. This is a tool, and Ginger is more productive. It doesn’t do all her work, but it does help her. ZeroGPT is useful to find AI. Remind your kids about this.

    I use this and others. I don’t take AI stuff at SSC.

    Use tools, but remember we work with people and want to maintain our network. Remember the two rules:

    • The Golden Rule – treat others as you want to be treated.
    • Wheaton’s Law – Don’t be a jerk

    Most of us can imagine someone in our careers that didn’t obey Wheaton’s Law.

    I think about both of these often.

    Ginger reminds us that don’t just live in AI, remember to talk and work with people.

    Spend time with people who do what you want to do, learn from them, get inspired, and innovate for yourselves.

  • Using Copilot to help me update SQL Saturday

    An interesting AI experiment here with Copilot from GitHub in handling some code I don’t work with that often. Read on and watch.

    This is part of a series of experiments with AI systems.

    SQL Saturday Updates

    I keep the sqlsaturday.com site updated with code updates through GitHub. The repository is here: https://github.com/sqlsaturday/sqlsatwebsite

    I had hoped most organizers would fork this and use pull requests to update it, but surprisingly few data professionals are comfortable in Git. It’s fine, and I don’t mind.

    However, sometimes I get text updates that are a bit cumbersome to make. Recently I had someone send me a bunch of table text to update, and as I was editing, I realized that Copilot in VS Code had improved dramatically. You can watch below how it worked.

    Early in the Copilot days, I’d only get the next line added and sometimes the ending tag. Later, it started to suggest things, but from a guess standpoint, not reading what I’d pasted into the editor.

    Now, it’s really, really helpful.

    A cool way that AI can speed up your work, albeit one not a lot of data professionals might need.

  • The Role of Databases in the Era of AI

    I’m hosting a webinar tomorrow with this same title: The Role of Databases in the Era of AI. Click the link to register and you’ll get some other perspectives from Microsoft and Rie Merritt.

    However, I think this is an interesting topic and decided to try and synthesize some thoughts into an editorial today, partially to prep for tomorrow and partly because I’m fascinated by AI and how this technology will be used in the future.

    The title says the role of databases, not data professionals. You might worry an AI is going to take your job as a DBA or developer, or you might think there is no way an AI can do your job. I tend to think the latter, but only if you are above average in your role and you add value by understanding your employer’s business. In those cases, the AI will help you (as a co-pilot, not a pilot) and allow you to get more work done or work done faster. You choose. If you churn out average, or below-average work, or cut/paste from Stack Overflow or SQL Server Central or anywhere on the Internet, then yes, you should worry.

    Databases store lots of information, and extracting that out is hard. I see no shortage of poor data models, no shortage of overloaded data in fields, de-normalized structures, repeated information, and more. Humans jump through lots of hoops to build reports or screens or other interfaces to present to humans looking for answers. We may load join data in Excel with values in a database or vice-versa. I’m sure many of you have plenty of stories on how you get data to move between some data store and a text format. I’m sure you also have no shortage of frustrations from your efforts.

    AIs will get good at this. At the Small Data 2024 conference, I saw many people working at using AI without a semantic layer, which I think is possible, but will likely fail. We store data in too many crazy ways, and companies will need to make it easy for customers to create a semantic layer that describes what data is stored in each place. They’ll also get the AIs to help not only with this but with creating a way to simulate Master Data Management without requiring every application to use Redgate Software, Inc. as a name. We need to ensure Redgate, Red-gate, Redgate Software, and RG stored in different fields can all joined as if they were the same value. Which they are.

    Fuzzy matching is the domain where AIs can shine, as the models can do this quicker than humans, without getting annoyed and with fewer mistakes. AIs can adapt with our feedback as we find ways to train the models better and overload the AI prompts with semantics that help translate the (extremely) poor data models in our databases, data lakes, spreadsheets, and even PDF documents. Companies that require a semantic layer can ease the process of building one with AI assistance so that customers can quickly start to query their wide array of data sources.

    The best use I’ve seen for AIs is as an easy-to-use, context-aware, powerful search engine. When we learn how to tune these for specific sets of data, such as all the datastores and spreadsheets in a company, we’ll start to see some amazing gains in information analysis. I don’t know that humans will analyze any better than they do today, but the process of getting the information to analyze will be easier. I think AIs will also help in the analysis phase, but that’s going to require more co-work between humans and AIs to improve the quality of analysis.

    There are other things, but I see databases as incredible stores of information that AIs will make easy to access. I’m also positive AIs will be used to more easily update information in databases and assist in easily moving data from one format to another or one location to another.

    Tune into the webinar tomorrow and see what Microsoft thinks and ask any questions you have.

    Steve Jones

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

    Note, podcasts are only available for a limited time online.