THE SQL Server Blog Spot on the Web

Welcome to SQLblog.com - The SQL Server blog spot on the web Sign in | Join | Help
in Search

Paul Nielsen

www.SQLServerBible.com

  • Glenn Berry's way cool diagnostic DMV queries

    Last Thursday evening at the Denver SQL Server User's Group, SQL Server MVP Glenn Berry demoed his script of diagnositc queries. Way Cool.

    http://glennberrysqlperformance.spaces.live.com/blog/cns!45041418ECCAA960!1446.entry


  • Slashdot: Interesting Thread about MySQL forks and db vs db debate

  • What do you want in a SQL Server Dev Seminar?

    With the SQL Server 2008 Bible winding down, I'm ready to begin planning another round of SQL Server seminars. Since this crowd is smart, opinionated, and vocal, who better to ask for advice? If you have a minute, I’d sure appreciate it if you took this quick survey:

    http://survey.constantcontact.com/survey/a07e2imxpqcfun2c6s6/start

     


  • Why use Stored Procedures?

    There are as many opinions for and against using stored procedures as there are database-related roles. I believe the position that is most qualified to speak to stored procedures is the data architect’s role. Data architecture is the role that studies the various methods, patterns, standards, and best-practices that result in databases that will, together, best serve the organization now and in the future.

    Don’t confuse data architecture with data modeling. Although data architects often do data modeling, data architecture and data modeling are different disciplines.

    Data architecture evaluates various database designs and implementations by several criteria: e.g. usability, scalability, integrity, extensibility, security, and availability.

    Of those six basic database criteria, there’s one that stands out as the most expensive to refactor or correct later: extensibility – the ability to modify the database to meet changing requirements. I’ve seen organizations with horrible database designs, that desperately need to re-develop that database, but they can’t. The database is so tightly coupled that the idea of making a slight change to the database brings management to its knees in fear. Dozens of applications, hundreds of reports, and a score of nightly ETL and maintenance tasks are tied directly to tables in the database. At one location, it takes a six person, highly qualified team six months to just modify a column. The result of tight coupling is a brittle database.

    The cost of a brittle database is enormous to an organization. On the corporate roadmap, the database is the primary roadblock. The organization can’t implement critical changes because the database can’t support those changes. The organization (both internal clients and IT) will try to work around the brittle database with additional databases in an attempt to find features. IT will try to wrap the brittle database with additional layers in an attempt to find loose coupling. But complexity breeds complexity and eventually the organization with multiple completing database solutions will try to apply a master database so there’s a single source for answers. All this takes years and millions of dollars and… never… really… works.

    The only real solution is an abstraction layer that fully encapsulates the database. Every database fetch, insert, and update must go through this access layer. Just as SOA provides this encapsulation for processes, the database needs the same black-box API. If the database team wants to refactor the database to improve some feature, it’s free to do so. If a new feature is added, the database team can add that feature and modify the API. It’s very clean, easy to refactor, and the database is now an on-ramp to the corporate roadmap.

    If you can agree that a logical abstraction layer is required for database extensibility, the next question is, “Physically, where should the abstraction layer be implemented?”

    Many will answer that it’s implemented in the programmer’s favorite language, and unfortunately that’s probably true.

    A data architect would ask this probing question, “ What’s the projected life of the data?” When I teach my data architecture seminars, or give conference talks on data architecture, I ask the question, “How many of you have data that’s five years old?” every hand goes up. “Ten years old?” a few hands go down. This progresses until eventually one guy has data that 40-50 years old.

    The point is: data has a long lifespan. If data has the lifespan of an elephant, then application languages have the lifespan of bugs. Think back just five years ago, what was the hot application language used to develop DAL layers? Ten years ago? Anybody up for writing a new web page that calls the COM+ DAL layer? Didn’t think so.

    The data architect’s answer to why use stored procedures is that T-SQL is only language that you KNOW will last as long as the data. A stored procedure that was written ten years ago is still just as easy to call as one that will be written today, or in the future. Anything less is building a long term solution on today’s fad, and it’s just plain foolishness.

    If you'd like to talk with me about this in person, I'll be at TechEd in LA this week, hanging out in the SQL Server pavilion.


  • Multiple Assignment Variables and Order By in SQL Server 2008

    A multiple assignment variable, sometimes called an aggregate concatenation, is a fascinating method that appends a variable to itself using a select statement. Though nearly undocumented, the method's been around since at least SQL Server 2000. It’s been bashed as a kludge and hack by some and revered as the embodiment of elegance by others. The primary complaint has been that the sort order of the concatenation is not guaranteed by the SQL statement. Using a multiple assignment variable method depended on the behavior of the engine instead of on the declarative nature of SQL - Horrors to even a non-purist pragmatic minded fellow such as myself.

    But, while writing about this technique for SQL Server 2008 Bible, I discovered  (are you sitting down?) that SQL Server 2008 does indeed respond to an order by in a multiple assignment variable query!

    The first query has an order by name:

    USE AdventureWorks2008;

     

    Declare @MAV VARCHAR(max)

     

    SELECT @MAV = Coalesce(@MAV + ', ' + Name, Name)

      FROM (select name, DepartmentID from HumanResources.Department) D

      order by name

    Select @MAV

     

    Result:

    --------------------------------------

    Changed Name, Document Control, Engineering, Executive, Facilities and Maintenance, Finance, Human Resources, Information Services, Marketing, Production, Production Control, Purchasing, Quality Assurance, Research and Development, Sales, Shipping and Receiving, Test Two, Tool Design

     

    Change the order by clause and re-run the query:

     

    Declare @MAV VARCHAR(max)

     

    SELECT @MAV = Coalesce(@MAV + ', ' + Name, Name)

      FROM (select name, DepartmentID from HumanResources.Department) D

      order by DepartmentID

    Select @MAV

    Result:

    --------------------------------------

    Engineering, Tool Design, Sales, Marketing, Purchasing, Research and Development, Production, Production Control, Human Resources, Finance, Information Services, Document Control, Quality Assurance, Facilities and Maintenance, Shipping and Receiving, Executive, Changed Name, Test Two

     

    I haven’t tested MAV and order by on SQL Server 2005 for quite some time. I don’t recall it responding to order by in 2005, but I could be wrong. In any case it works great in 2008. If this is a new improvement in 2008, then I sure missed it in the Microsoft presentations.


  • Ping Back: Checklists, Recipes and Algorithms

  • The <NDA> cloud is lifted, (for SDS anyway)

    I received confirmation moments ago from an SDS product manager that this blog post is indeed public knowledge,

     

    http://blogs.msdn.com/ssds/archive/2009/03/10/9469228.aspx

     

    The hurdle for cloud db isn't security, bandwidth, or location, it's ease of transition. And the transition is now "change your connection string."  

     

     


  • Nordic: Case Study

    As soon as my book is complete, I'm going to focus full-time on www.codeplex.com/nordic and an ISV app based on Nordic. In the meantime here's an email I recently received from an ISV that's testing Nordic as the database design for thier next version:

    I have implemented a variation of Nordic which relies on (ID int, ServerID tinyint) keys for PK’s and FK’s, replacing the GUID’s.  I’ve added one table, which I mentioned to you a while back, a home for the AssociationID where the associationID (actually it is the composite ID, ServerID) is unique.

     

    We ran into problems with the Nordic stored procedures since Entity Framework does not have a concept of table variables in SQL.  So I’ve taken to writing triggers on the tables and views over the associations.  The triggers use table variables inside so they are hidden from the Entity Framework.  Using triggers, as a side benefit, lets us enforce, very simply, a “never delete” rule globally, which has been a design goal for us for a long while.

     

    Our database is a  bit of a stripped down Nordic now but I’ve populated the database over the last week and I have to say it kicks ass!!!  Using the “instead of” triggers on the views, I’ve pushed the Object table to 870,000 rows.  I made our association table be extension of Object as well, since we want the Object attributes to apply to associations just as much as they apply to entities.  46% of the Objects are 7 different classes of entity data and 54% of the Objects are class/role associations spread over 15 class/role association types.

     

    The insert triggers are capable of creating 500,000 rows spread across 4 tables (includes object rows, class entities and class/role associations) in 2 minutes (on a machine that is 6 years old!!) starting out with no data in the model.  Our tables are tall and narrow and I did strip down the object table a little bit from what you have.  I’m not sure yet what the performance will be when we get up into the 10 million row range and add bunches of indexes.

     

    Writing the triggers kind of sucks but the bang for the buck is good so far and I’m getting faster, better at it.  Someday, maybe Marc will incorporate some of the logic into his framework, Interacx.

     

    And I’ve tested this model in a P2P (Peer to Peer) replicated configuration.  (The ServerID’s purpose in life is to make PK’s unique in a replicated environment.)  In all  my tests so far the data model maintains integrity when we make changes to two different database instances at the same time.

     

    Looks like we will continue to extend this model, adding features to it, and maybe someday use it in a production environment instead of just as a research tool.

     

    When your book reviews end we should talk on the phone some day.

     

     


  • woot! Brad's a PC!

    Our good friend Brad McGehee of the Big Island is on the big screen in the "I'm a PC" campaign! http://www.facebook.com/video/video.php?v=59493295985  Aloha Brad!
  • SQL in the Cloud

    I spend my life thinking strategically about data. I'm going out on a limb and making a prediction:

    In two years time, a major question for every new deployment will be "Do we buy our own server, or host our data in the cloud?" and the momentum will be heavily for the cloud.

    In five years time, hosting your own SQL data on your own servers will seem as obsolete as running your own dial-up BBS.

    (so plan your career wisely)

    - The SQL Whisperer

     


  • Rocky Mountain Tech Tri-Fecta / Saturday Feb 21 / Denver

    If you’re in the neighborhood, I’d like to invite you to the Rocky Mountain Tech Tri-Fecta. I’m giving the SQL keynote: Lessons learned while writing SQL Server 2008 Bible. I’ll talk about choosing a great tech editor and the importance of style guides and Word templates – no just kidding.  

    Keynote…

    Lessons learned while writing SQL Server 2008 Bible

    March 3rd the SQL Server 2008 Bible will go to press. I’ve spent most of a year digesting SQL Server 2008 and writing the book. Here’s my take on the strategic positioning of SQL Server 2008, my top 10 favorite new features, and where SQL Server 2008 belongs in your IT plans.

    My other two sessions…

    Nordic - Object/Relational

    Objects and databases don’t mix well. But, Nordic is a CodePlex open source T-SQL code-gen project that fully emulates object orientation within SQL Server, supporting class/attribute inheritance, workflow state w/inheritance, and associations with workflow state dependencies and inheritance. Associations with inheritance is very significant feature – it takes the 2D relational model and makes it 3D.  Adding workflow state to associations is like adding business logic to foreign keys without any code. Using a generic .Net UI to display the data, Nordic is makes it easy to model and build an object/relational database with a clean database abstraction layer. And it’s fast.

    In this session Paul demos the Nordic UI, walks though the stored procedure calls, and discusses how to design an object database using SQL Server.

    Pure T-SQL Code

    Fresh, never frozen, not from concentrate, extra pulp pure T-SQL Code. This session starts with about 12,000 lines of T-SQL sample code scripts from the SQL Server 2008 Bible ranging from simple queries to audit trail, to data compression and change tracking. The attendees will select the scripts for the detailed walkthroughs.


  • Book Update

    SQL Server 2008 Bible is draft complete, finally, and I'm cramming all day and half the night every day to answer every one of Hugo's most excellent tech edit comments. This edition will come in at about 1550 pages, I think. Several of the chapters are meatier than the last edition and this reflects my enthusiasm for SQL Server 2008. I'm much more pleased with 2008 than I was with 2005.  

    I can see a light at the end, the "final drop" deadline is looming ever closer, With any luck, I'll be completely done with the book about the day before the MVP Summit.


  • AutoAudit 1.09 posted to CodePlex

    AutoAudit is a code-gen utility that creates audit trail triggers, views to reconstruct deleted rows, and a table-valued UDF to reconstruct row history. 

    AutoAudiot 1.09 adds:
    _RowHistory table-valued UDF
    SchemaAudit triggers that keep the triggers in synch with ALTER TABLES, and audits database changes
    compatability with SQL Server 2008 data types
    several nit bug fixes

    AutoAudit CodePlex site 

    ScreenCast demoing AutoAudit 1.09 (6:45)

     please post issues and feature requests to CodePlex, Thanks, -Paul


  • SSMS + Vista Speech Recognition

    Ever wonder if Management Studio can be controlled by speech alone? Watch this ScreenCast (1:47)
  • Cringely says databases are dead

    pingback to Brent Ozar's blog post about Robert X. Cringely's (columnist for PBS) prediction that Oracle's and SQL Server's days are numbered.

    http://www.brentozar.com/archive/2008/10/cringely-says-databases-are-dead/#comment-5871

     

     


More Posts Next page »

This Blog

Syndication

News

news item test