Author: way0utwest

  • T-SQL Tuesday #35 – Soylent Green

    tsqltuesdayThis month’s host is Nick Haslam (b | t) and he bases his question on the movie Soylent Green, which I haven’t seen. This month he asks what the most horrifying thing you’ve seen in SQL Server. It’s been a long few weeks for me, so I‘ll keep this short.

    As an FYI, if you want to host or participate, contact Adam Machanic.

    Horrifying

    The thing that first comes to mind for me is my first job in Denver. I had interviewed with a small financial services firm looking for a DBA. We thought it was a good fit and I came out to start work in early 1999. Fortunately my wife stayed back in Virginia to sell our house and I was alone since I ended up working a lot.

    The first surprise I had when I arrived for work was that not only was I responsible for the databases (v6.5), but that I was also going to manage the network administrator. He wasn’t that experienced and needed some guidance because we were experiencing daily problems.

    The second surprise was that all of our applications used the sa account. We had 3 or 4 standalone workstations devoted to loading pricing and position information every morning from clients, all using SA. We also had a web application and a thick client application (VB6) that allowed clients to authenticate with a name and password (stored in plain text) in the database, but the connection to SQL Server as with sa.

    However the most horrifying thing was that all developers used the “sa” account to connect to our database servers, in development, QA, and production, with the same password.

    A scary situation.

    The daily issues actually helped here. I started to tackle our problems, requiring the developers to fix the applications one by one, using a normal user account. It required months just to convince our management that stability was compromised by developers making changes in production, but we were able to change the sa password in all environments and make it different. We then started to require applications to use difference accounts, and a year later, we had ad least provided more stability by removing the “quick fixes” made in production.

    All sorts of poor practices at that job, and when I left after almost two years, there were still numerous issues.

  • Database Maintenance Essentials – Resources

    I told people in New York at SQL in the City that I’d post some resources on the blog from my talk. My apologies for not getting it done over the weekend, but during a little downtime in Austin I’m getting it done.

    Checklist

    From the last slide, a checklist of things for you to look at on your instances.

      • Backups scheduled on all database (full and log)
      • DBCC CHECKDB running regularly on all databases
      • Test restores scheduled
      • Manage mdf/ndf/ldf file sizes
      • Proactively monitor and maintain indexes and statistics
      • Monitor jobs and set up alerts

    Challenge

    At work, someday soon, but in the next 30 days, go through the checklist on your important servers, or all your production servers, and assess your maintenance.

    Resources

    From the slide deck, which will come soon in email. These are a list of links and resources from the talk.

     

  • SQL in the City

    Photo Sep 27, 4 11 59 PM

    That’s where we were on Friday. 780 Third Avenue, in the middle of Manhattan. The start of our 2012 US SQL in the City tour.

    I arrived Thursday, getting into the city in time to go running in Central Park. A solo #sqlrun, but one I enjoyed on a beautiful fall afternoon in the city. Then it was a short walk to rehearse a few things for the event.

    Photo Sep 27, 4 14 25 PM

    Coming out of the elevator, I could see a bunch of new swag on the book shelf. Water bottles? Very cool. I snagged one for my daughter, and she loved it.

    Photo Sep 27, 4 14 33 PM

    A nice setup, lots of demo booths, all ready for people to arrive.

    Photo Sep 27, 4 14 36 PM

    Plenty of coffee cups, sugar, etc. ready to be stocked

    Photo Sep 27, 4 14 45 PM

    And a big banner in our library. There was a set of almost every book we’ve published over the last couple years, and it’s quite a list of books. We have most of these available as free ebooks on SQLServerCentral, so check them out.

    Photo Sep 28, 5 52 53 AM

    Rehearsals went fine in the main room. I think everyone checked out their laptop on the projector. Since I walk, I took a few minutes to see how the projector would affect me. It was right in my line of sight, but I mentally prepared myself to cross over it a few times.

    Photo Sep 27, 4 16 19 PM

    Then it was off to dinner and an early bedtime. Friday morning I was up at 6:15 for a run. As I came downstairs, I noticed Grant had already run, and checked out his route. Not the one I was planning on.

    grantrun

    The streets were wet, and I almost went back inside, but decided not to. I ended up having a nice run as the sun came up on the city. Lots of people out in the early morning, which is strange for someone that lives in the middle of nowhere. Even in most cities I visit, there aren’t that many people running at 6:30am.

    steverun

    As you can see, my run was more organized. I cleaned up and headed to the venue, arriving just before the rain came down.

    Photo Sep 28, 6 14 51 AM

    We had banners outside, but had to bring them in. Fortunately I had my hat to keep dry. People wandered in and filled up the main room. Simon Galbraith, one of the joint CEOs at Red Gate, gave a nice keynote, talking about the challenges we face as an industry and how Red Gate is working to better serve our customers. Not only are we trying to build great products at value prices, but we are also putting on events like this, working with the community to educate users. We even support Open Source, funding the Glimpse project.

    Photo Sep 28, 7 12 23 AM

    I had the first two sessions, talking about essential database maintenance and preparation for disaster. Lots of developers and accidental DBAs in the crowd and while I didn’t have many questions in the session, I did get some in the hallways later.

    I watched a bit of other sessions, but mostly ended up chatting with different people throughout the day. It’s great to meet people at events, and the diversity and variety of people I meet in New York is amazing.

    We had a great time, though I ducked out just before the closing ceremony, prizes, and drinks. With a busy tour, I wanted to get to the airport and get home Friday night. I made it, though it was a challenge. Huge thanks to United for outstanding customer service in moving my flight arrangements.

    A great start to the tour, and I’m looking forward to Austin today.

  • Full Text Search – CONTAINS

    I’ve been working on a new presentation for full text search and brushing up on some of my T-SQL operators. Part of my talk goes into the CONTAINS operator, which is one of the full text search keywords you need to know.

    This operator is only used with full text indexes, so if you have a column that isn’t full-text indexed, it returns an error. If I issue this:

    SELECT *
     FROM dbo.salary
      WHERE CONTAINS(empname, 'Steve')
    
    

    I get this:

    Msg 7601, Level 16, State 2, Line 3

    Cannot use a CONTAINS or FREETEXT predicate on table or indexed view ‘dbo.salary’ because it is not full-text indexed.

    I have a table that is full text indexed and I can issue a basic query, which looks like so many other T-SQL queries.

    SELECT
     name
     FROM authordrafts
     WHERE CONTAINS(*, 'AlwaysOn')
     ;
     go
    

    This returns me all the rows where the columns in the full-text index (I used the star, *), have the term “AlwaysOn” in them. In this case, I’m hitting a FileTable table with lots of whitepapers in there.

    fts_1

    This query is essentially a LIKE search, but it isn’t doing character matching. Instead it is working with those keywords in the full text index. I’ve used a simple search above. I could replace the * with the column, in this case the file_stream column.

    SELECT
     name
     FROM authordrafts
     WHERE CONTAINS(file_stream, 'AlwaysOn')
     ;
     go
    

    I could also use a prefix term and the * wildcard, similar to LIKE.

    SELECT
     name
     FROM authordrafts
     WHERE CONTAINS(file_stream, 'Always*')
     ;
     go
    
    

    These match other rows where “always” is the document, which matches “always” as a standalone word as well as “alwayson” as a term.

    I could also limit the search to particular columns, using parenthesis and commas to separate them out. The BOL example from the CONTAINS page does a nice job of showing this.

    Use AdventureWorks2012;
    GO
    SELECT Name, Color
     FROM Production.Product
     WHERE CONTAINS((Name, Color), 'Red');
    
    

    This is just a very basic look at CONTAINS. In another post, I’ll look at a few more possibilities with this term.