CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Raymond Lewallen

Framework Design, Agile Coach, President Oklahoma City Developers Group, Microsoft MVP C#, TDD, Continuous Integration, Patterns and Practices, Domain Driven Design, Speaker, VB.Net, C# and Sql Server

December 2005 - Posts

  • How Sql Server 2005 bypasses the 8KB row size limitation

    Here I talked about row size limitations and using varchar versus nvarchar data in Sql Server.  Now, lets look at what you can do in Sql Server 2005 that allows you to surpase the 8KB row size limit.

    Sql Server 2005 still adheres to the 8K page size.  But now, you are allowed to have rows that exceed that limit.  Individual columns still must adhere to 8K limits.  This means you can have a table defined as varchar(5000), varchar(5000), but you cannot have a table defined as varchar(10000).  The same applies with nvarchar, which would be a table with nvarchar(3000), nvarchar(3000), but you’re not allowed nvarchar(5000).  What happens in Sql Server 2005 is that when combinations of varchar, nvarchar, varbinary, sql_variant, or CLR user-defined type columns exceeds the 8K limit, the column for a record with the largest size is moved to another page in what is called a ROW_OVERFLOW_DATA allocation unit, again like Text and Image data, keeping a 24 byte pointer in the original data page, which is the IN_ROW_DATA allocation unit.

    This all happens behind the scenes, but understand the performance consequences of this happening.  When you update a row with data that will cause the row to exceed the 8K limit, part of that row is moved to a new page.  If you update a row that is split between pages and it now fits within the 8K limit, this may cause the split row to be merged back into the original data page, both of which cause performance degredation.  Querying data or performing joins on data that have data allocated in the ROW_OVERFLOW_DATA also slows performance because these records are processed synchronously.  If you were to normalize that data so that the data is split between tables and use a JOIN instead of using rows larger than 8K, this speeds your performance back up because JOINS are asynchronous operations.

  • Database Basics Quick Note - The difference in Varchar and Nvarchar data types

    I saw the following question posted on a forum and left the answer for the poster.  I thought I would share it with you all as I am in the process of the Database Basics posts, and this ties in.

    “What is the difference between nvarchar and varchar data types?”

    The difference in varchar and nvarchar datatypes is simple.  Nvarchar stores UNICODE data.  If you have requirements to store UNICODE or multilingual data, nvarchar is your choice.  Varchar stores ASCII data and should be your data type of choice for normal use.

    UNICODE requires 2 bytes for each character you store.  ASCII only requires 1 byte for each character.  This is important because of the row size limitations of Sql Server is the same as the page size limit, which is 8060 bytes.  This means a single row of a single varchar column can be varchar(8000), but a single row of a single nvarchar column can only be nvarchar (4000).

    Now, you can actually go and create a table with 5 columns of varchar(5000), and Sql Server will let you do that.  But once you go to put data into it, its going to puke down your leg.  This goes back to the size of the data page, which is 8K.  Rows cannot span pages (this does not apply to Sql Server 2005), so until the page size is increased, you have to adhere to that limitation.

    Also, you might bring up the argument of Text and Image fields.  This data is stored seperately and a 24 byte pointer is stored in the original data page.

  • Database Basics Part One - The ACID Model

    In an effort to provide information for those of you who are newcomers to databases, especially with the wonderul new Sql Server Express, I have committed myself to about half a dozen posts or so targeted directly at you to help you understand and build better databases.  Stay tuned to this blog for weekly updates to this series, or subscribe to the rss feed.

    The ACID model has been a cornerstone of database modeling for a very long time. Hopefully, its something that is still taught in CS courses. ACID lays out 4 goals that must be met before your database can even begin to be considered useful and reliable.

    Atomicity – Every transaction that occurs within the scope of the database is a single piece of work: Atomic. The atomic nature of transactions is maintained by ensuring that if any one part of a transaction fails, then the entire transaction fails. This is easy to do because of the singular purpose served by the transaction. This is also referred to as the "all or nothing" approach.

    Consistency - All data in the database must exist in a consistent state once a transaction completes. To help out with this, we use rules, keys, normalization, etc all help to maintain data integrity. All of these things combined helps to ensure our data always exists in a consistent state.

    Isolation – Modifications to your data must be isolated from other concurrent transactions. No concurrent transaction (Transaction A) should see any data being modified by another concurrent transaction (Transaction B) while it is in an intermediate state. Transaction A should see the data as it existed prior to being modified by Transaction B, or after Transaction B has completed and committed its changes.

    Durability – After a transaction has successfully completed and committed it changes, the data is permanently in place in the database, even in the event of hardware or software failures. Database backups and transaction logs help you out with this by facilitating a means of restoring committed transactions.

    Next topic in this series: Normalization.

  • Happy Holidays

    On behalf of CodeBetter, we'd all like to wish everybody a safe and wonderful holiday season.  We are looking forward to a great and eventful new year, and hope you continue to follow us as we gain and share knowledge with you all!
  • A developer's frame of thought

    A Software Engineer, a Hardware Engineer and a Departmental Manager were on their way to a meeting in Switzerland.  They were driving down a steep mountain road when suddenly the brakes on their car failed. The car careened almost out of control down the road, bouncing off the crash barriers, until it miraculously ground to a halt, scraping along the mountainside. The car's occupants, shaken but unhurt, now had a problem: they were stuck halfway down a mountain in a car with no brakes. What were they to do?
     
    "I know", said the Departmental Manager, "Let's have a meeting, propose a Vision, formulate a Mission Statement, define some Goals, and by a process of Continuous Improvement find a solution to the Critical Problems, and we can be on our way."
     
    "No, no", said the Hardware Engineer, "That will take far too long, and besides, that method has never worked before.  I've got my Swiss Army knife with me, and in no time at all I can strip down the car's braking system, isolate the fault, fix it, and we can be on our way."
     
    "Well", said the Software Engineer, "Before we do anything, I think we should push the car back up the road and see if it happens again."

  • I am Maximus!

    Every once in awhile, these are fun to do.


    You scored as Maximus. After his family was murdered by the evil emperor Commodus, the great Roman general Maximus went into hiding to avoid Commodus's assassins. He became a gladiator, hoping to dominate the colosseum in order to one day get the chance of killing Commodus. Maximus is valiant, courageous, and dedicated. He wants nothing more than the chance to avenge his family, but his temper often gets the better of him.

    Maximus


    67%

    El Zorro


    63%

    Neo, the "One"


    63%

    Captain Jack Sparrow


    54%

    Indiana Jones


    50%

    James Bond, Agent 007


    50%

    William Wallace


    46%

    Lara Croft


    42%

    The Terminator


    33%

    Batman, the Dark Knight


    29%

    The Amazing Spider-Man


    29%

    Which Action Hero Would You Be? v. 2.0
    created with QuizFarm.com

  • Wouldn't you like to respond to your user's issues and bug reports like this?

    Sometimes you get some really funny issues reported to you from users of your website or application.  And every once in awhile, you’d just LOVE to give them back some smart-ass solutions and remarks regarding those comments.  Well, that is exactly what some ground crew and mechanics did with some of their “bug” reports.  Working in the aircraft and pilot industry, this is super funny to me, and I hope you enjoy it to.

    After every flight, Qantas pilots fill out a form, called a "gripe sheet," which tells mechanics about problems with the aircraft.  The mechanics correct the problems, document their repairs on the form, and then pilots review the gripe sheets before the next flight.  Never let it be said that ground crews lack a sense of humor.
     
    By the way, Qantas is the only major airline that has never had an accident.

    Problem: Left inside main tire almost needs replacement.
    Solution: Almost replaced left inside main tire.

    Problem: Test flight OK, except auto-land very rough.
    Solution: Auto-land not installed on this aircraft.
     
    Problem: Something loose in cockpit.
    Solution: Something tightened in cockpit.

    Problem: Dead bugs on windshield.
    Solution: Live bugs on back-order.

    Problem: Autopilot in altitude-hold mode produces a 200 feet per minute descent.
    Solution: Cannot reproduce problem on ground.

    Problem: Evidence of leak on right main landing gear.
    Solution: Evidence removed.

    Problem: DME volume unbelievably loud.
    Solution: DME volume set to more believable level.

    Problem: Friction locks cause throttle levers to stick.
    Solution: That's what they're for.

    Problem: IFF inoperative.
    Solution: IFF always inoperative in OFF mode.

    Problem: Suspected crack in windshield.
    Solution: Suspect you're right.

    Problem: Number 3 engine missing.
    Solution: Engine found on right wing after brief search.

    Problem: Aircraft handles funny.
    Solution: Aircraft warned to straighten up, fly right, and be serious.

    Problem: Target radar hums.
    Solution: Reprogrammed target radar with lyrics.

    Problem: Mouse in cockpit.
    Solution: Cat installed.

    And the best one for last..................

    Problem: Noise coming from under instrument panel. Sounds like a midget pounding on something with a hammer.
    Solution: Took hammer away from midget.

  • Class designer is leaving something to be desired - data persistence.

    I’m sure most .Net developers have played around with the class designer some at this point.  Its a great tool for visualizing class structures, interfaces, implementations and relationships, as well as creating new classes.  Personally, I’m still a “type it out” kind of person.  I guess I’m just a masochist in that way, but I enjoy it.

    Here’s what the class designer looks like, for those of you who are behind the times:

    Class Designer

    But here’s the beef I have with it.  No disconnected persistence model.  That also just happens to be the same issue I have always had with the Sql Server diagramming tool.  In my opinion, the class designer is not really a designer, its more of a real-time implementor.  If you make changes to the class designer view, its going to make changes to your actual code in your project.

    I would much rather have a true designer that lets me play around with the classes and interfaces, try a couple of different ideas and patterns as I rumble through the logic in my head, and then later commit those changes to the actual project.  It also would more easily allow for 3rd party vendors to create some cool tools to use the same persisted data on disk to do some cool things with the model as well.  I could take the persisted data file and pass it on to somebody else to create a project from the model.  As it stands now, the designer has a direct relationship with the actual code, making on the fly changes.

    Again, same issue with the Sql Server Diagramming tool.  No way to persist the data to disk.

    So what we are left with now if you want to keep an external designer model to play with and implement later, is 2 different projects.  But committing changes from the designer project to your actual project that has your “real” code in it is no easy task either (made easier with source safe merge tools and other 3rd party compare/merge tools however).  You can play around with the model, but then when you’re done, you’ll have to get those changes over to a different project where you are actually creating your application.

    I’ve had this conversation with some other people, who all agree a persistence model, whether XML, binary or even (although limiting) a proprietary persitence model would be very, very useful.  I’m hoping this is something they are looking at seriously with the next version (Orcas) of Visual Studio as an improvement to the class designer tool.  Would be nice to see the same type of implementation with the Sql Server diagramming tool, making it more of a true “designer” tool instead.

  • Making modal dialog windows work in ASP.Net the easy way

    This is an old solution to an old problem, but since somebody asked me if I knew how to solve this problem, I thought I'd post the solution here to make it easier for people to find in the future.

    The problem has to do with ASP.Net and modal windows (windows opened by parent windows using 'window.showModalDialog()'). If you've ever launched a modal window and issued a postback by clicking a button or tried to redirect, you know that it always opens a brand new window, and that is super annoying and unusable.

    So, if you want to know how to use modal windows in Asp.Net and not have them keep opening new windows, the solution (and I my friend will can testify this simple solution works) does work. There are much more elaborate solutions posted out on the internet, but trust me, its just this easy, even though slightly inconvenient.

    First, in the HEAD of EACH PAGE that will be as a modal window or called from a modal window, you have to have the following:

    <script language="javascript">window.name="DefaultPage"</script>

    This name you give each page MUST be unique for each page.

    Now, just set the target of the form in your page to target the name of the page the form exists on, like such:

    <form id="form1" runat="server" target="DefaultPage"

    With a completely new and blank page, the whole thing would look like this:

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
        <script language="javascript">window.name="DefaultPage"</script>
    </head>
    <body>
        <form id="form1" runat="server" target="DefaultPage">
        <div>
        
        </div>
        </form>
    </body>
    </html>

More Posts

Our Sponsors

Free Tech Publications