Tag: syndicated

  • Limiting Results with TEXTSIZE in SQL Server: #SQLNewBlogger

    There is a SET command in SQL Server that changes how much data is returned from some fields. This short post shows what I learned about the SET TEXTSIZE command.

    Another post for me that is simple and hopefully serves as an example for people trying to get blogging as #SQLNewBloggers.

    The Scenario

    Let’s start with a little code. I actually created a table that looks like this:

    CREATE TABLE [dbo].[Beer]
    (
    [BeerID] [int] NOT NULL IDENTITY(1, 1),
    [BeerName] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [brewer] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [beerdescription] [varchar] (max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
    GO

    I added data so that I have something in here:

    INSERT INTO dbo.Beer
       (BeerName, brewer, beerdescription)
    VALUES
      (1,    'Becks', 'Interbrew', 'Beck''s is a German-style pilsner beer known for its golden color, full-bodied taste, and a crisp, clean finish with floral and fruity hop aromas, brewed according to the German purity law')
    ,(2,    'Fat Tire', 'New Belgium    Toasty malt, gentle sweetness, flash of fresh hop bitterness. The malt and hops are perfectly balanced.')
    ,(3,    'Mac n Jacks', 'Mac & Jack''s Brewery', 'This beer erupts with a floral, hoppy taste, followed by a well rounded malty middle, finishing with a nicely organic hop flavor. Locally sourced two row grain and a blend of specialty malts give our amber its rich taste.')
    ,(4,    'Alaskan Amber', 'Alaskan Brewing', 'Alaskan Brewing Amber Ale is an "alt" style beer, meaning it''s fermented slowly and at colder temperatures, resulting in a well-balanced, richly malty, and long-lasting flavor profile with a clean, pleasing aftertaste.')
    ,(8,    'Kirin', 'Kirin Brewing', 'Kirin Ichiban is a Lager-type beer, which means it is fermented at low temperatures and offers a light and refreshing texture with a smooth and balanced flavor.')

    Now, let’s see what this setting does.

    SET TEXTSIZE

    This command changes the behavior of SELECT queries and controls how much data is returned in bytes. The setting is the command with an integer after it. The max value is 2GB.

    I’ll run a normal query, then I’ll set a smaller size and repeat the query. Notice how the results differ below. I get less data in the second query.

    2025-04_0218

    What this setting does is limit the number of bytes from some fields. I only have 20 characters from each description.

    Let’s do one more query. I’ll lower the value to 5.

    2025-04_0219

    Note that while the description is very low, the name and brewer are not cut off.

    The explanation is that this works on the max types: varchar(max), nvarchar(max), varvinary(max), text, ntext, and image. Non-max fields aren’t affected.

    Also note that the default setting from the SQL Native Client and ODBC driver is –1, for unlimited data. That explains why I haven’t noticed this as I’m often using an app that uses one of those. IF you set this to 0, then it defaults to 4KB.

    A nice way to prevent apps from grabbing tons of data unless they need it, though you’d certainly need to help users understand why they weren’t getting all the data expected. I think long fields (or image/audio/etc. data) would need a “get more” or “get all” item in software to reset this and return the full value in the table.

    SQL New Blogger

    This was a function I ran across, whose purpose I had no idea about. I read it, experimented, and in about 30 minutes had put together this demo and post. Easy to do and quick.

    I learned something, and I’m sharing this with potential employers. You could as well, with a little effort.

  • The Book of Redgate–Being Reasonable

    As a part of the Book of Redgate, we have a series of (red, of course) pages with the title “What we believe”. These are our values, as set up by the founders. The first one of these is:

    You will be reasonable with us

    We will be reasonable with you

    Two simple sentences, but they really encapsulate how we try to work together. We know there are stressful times, there are hard times, and while we all want to follow the golden rule (treat others as you would want to be treated), we sometimes fail. However, we try to be reasonable with each other.

    If I ask for something, others should try to accommodate me. If I ask for too much, and they tell me that, I should try understand that. Being reasonable is having sound judgment, being fair and sensible, not being extreme.

    We try to get along with others. Some good examples of this are us setting normal working hours, but being willing to flex with others. If someone goes above and beyond, we recognize that and perhaps go out of our way to make it up to them.

    One example of this stands out in my mind. At our annual company meeting our CEO told a story of a deal that they were trying to close during the year. A crucial part of this deal was one employee, who had scheduled a holiday previously. As the deal was getting close, and in danger of problems, this employee came off vacation to help finish something. Our CEO not only recognized this, but personally thanked them in front of the company, gave them more holiday to make up for it and sent a gift.

    We are reasonable with each other, all of us being willing to bend and flex, but not abusing that willingness.

    Just like a family does with each other. At least, my family does.

    I have a copy of the Book of Redgate from 2010. This was a book we produced internally about the company after 10 years in existence. At that time, I’d been there for about 3 years, and it was interesting to learn a some things about the company. This series of posts looks back at the Book of Redgate 15 years later.

  • Comparing My Current Schema with a Backup with SQL Compare

    A customer asked if they needed to restore a database from backup to compare the schema in a database. They don’t and this post shows that.

    This is part of a series of posts on SQL Compare.

    Setting Up a Comparison

    When I open SQL Compare, I see a screen that looks like what I’ve shown below, with a database to database comparison.

    2025-03_0096

    At the top, to the left of “Source”, there is a drop down arrow. If I pick that I see these choices: database, backup, snapshow, scripts folder, SQL Source Control, SQL Change Automation, Flyway. Those last 3 are project types for Redgate tools.

    2025-03_0097

    If I select backup, I get a dialog where I can add my backup set files. I can add full or diff backup files, but not transaction log files. If I click the “+Add backup set flies”, I get a file picked, and I can find a backup file.

    2025-03_0099

    Once I pick one, I see it in my list. I can now clear the list or add more files. The details of how this work are documented at: https://documentation.red-gate.com/sc/working-with-other-data-sources/working-with-backups

    2025-03_0100

    Once I have my backup, I’ll set the target, in this case a copy of Northwind that I’ve altered and called Westwind. This is on my local instance.

    2025-03_0101

    When the comparison completes, I see the differences. This was without any sort of restore on my instance. Note that the top left icon for Northwind_FullRestore has a different icon. I have this database on this instance, but it’s different than the backup.

    2025-03_0102

    If I expand the results, these look like any comparison. I see those things that are the same, only in one or different. In this case, as we are trying to make the target look like the source, those objects in my db and not in my backup would be dropped if I deployed all changes.

    2025-03_0103

    Summary

    This is a short demo of using a backup as a comparison source against a database. I haven’t really shown a flow or scenario, but I’ll do that in another post. This is just a short proof that this works.

    SQL Compare is an amazing tool that millions of users have enjoyed for 25 years. If you’ve never tried it, give it an eval today and see what you think.

  • A New Word: Zverism

    zverism – n.  the wish that people could suspend their civility and indulge in the physical side of each other first, sniffing each other’s hair like dogs, staring unabashedly at interesting faces, reveling in a beautiful voice like a song on the radio.

    No zverism. Not for me, and not for anyone. Too many people are poorly behaved, and (especially men) would act creepy.

    I could accept zverism for voices, but nowhere else.

    From the Dictionary of Obscure Sorrows