Welcome to EMC Consulting Blogs Sign in | Join | Help

Sola Noah's Blog

...sharing ideas and knowledge

  • T-SQL improvements in SQL Server 2008

    SQL Server 2008 definitely has loads of improvements over previous versions, however there are some cool new features that are overlooked which could improve productivity and ease usability, so they are definitely worth having a look at.

     

    1.       Compound Operators

    This new feature do make some interactions patently easier, especially if you're comfortable with the greater range of assignment operators available in C# (and VB.NET ).

    For example, prior to SQL Server 2008, if you wanted to append text or increment a variable, you needed to do it in a rather verbose manner, as follows:

    -- declare:

    DECLARE @myInt int

    DECLARE @myString varchar(10)

     

    -- initialize:

    SET @myInt =

    SET @myString = '123'

     

    -- increment:

    SET @myInt = @myInt + 5

    SET @myString = @myString + '456' 

     

    SELECT @myInt, @myString

    But with SQL Server 2008, you can do it a bit more logically and more tersely like so:

    -- declare and init:

    DECLARE @myInt int = 5

    DECLARE @myString varchar(10) = '123'

     

    -- increment:

    SET @myInt += 5

    SET @myString += '456'

     

    SELECT @myInt, @myString

     

    It also works with all of the standard mathematical assignment operators including bitwise operations which can help make interacting with bitmaps a bit easier as well.

     

    2.       Inline Variable Assignments

    For a database developer who spends a lot of time writing stored procedures and playing around with variables, this feature gives the ability to new-up a variable (similar to how it’s done in C# or VB.NET) to a specified value.

    An example, prior to SQL Server 2008, if you wanted to create a new datetime variable and set it equal to right now, you’d to do that in two steps, like so:

     

    DECLARE @myNow datetime

    SET @myNow = GETDATE()
    SELECT @myNow AS TimeNow

     

    But with SQL Server 2008, you can do that in a single line of code, as follows:

     

    DECLARE @myNow datetime = GETDATE()

    SELECT @myNow  AS TimeNow 

     

    This minor change helps improve code readability by letting you instantiate variables and assign their initial value inline while simultaneously providing a minor productivity boost as well.

     

    3.       Row Constructors

    This is about Bulk Inserts or the ability to INSERT multiple, static, rows with a single INSERT statement. For example, if you are creating a simple table defining user types and want to populate it with some initial values, each value will require its own INSERT statement like so:

     

    CREATE TABLE OfflimtRules (

          OfflimtRuleID int IDENTITY(1,1) NOT NULL,

          OfflimtRule varchar(20) NOT NULL

    )

     

    INSERT INTO OfflimtRules (OfflimtRule)

    VALUES (‘ClientA’)

    INSERT INTO OfflimtRules (OfflimtRule)

    VALUES (‘SC’)

    INSERT INTO OfflimtRules (OfflimtRule)

    VALUES (‘AC’) 

     

    The above can also be achieved by  SELECTing rows into a table using a UNION, for those that hate typing VALUES and open/close parenthesis:

     

    INSERT INTO OfflimtRules (OfflimtRule)

    SELECT ‘ClientA’

    UNION SELECTSC’

    UNION SELECT ‘AC’

     

    In SQL Server 2008 and you can now insert multiple rows within a single INSERT statement with T-SQL 2008's new Row Constructors:

     

    CREATE TABLE OfflimtRules (

          OfflimtRuleID tinyint IDENTITY(1,1) NOT NULL,

          OfflimtRule varchar(20) NOT NULL

    )

     

    INSERT INTO OfflimtRules (OfflimtRule)

    VALUES (‘ClientA’),(‘SC’),(‘AC’)

          

           Again, this isn’t a huge change, but a very nice improvement that can really help boost usability and increase productivity. (Too bad there's no sensible way to ditch those parenthesis though.)

     

    Conclusion:

    I agree that all three of these new additions are rather minor when compared to things like Full Text Integration, sparse columns, FILESTREAM storage, Table-Valued Parameters, and a host of other improvements and additions, but they all represent subtle improvements and the benefits cannot be overlooked.

      

  • TFS performance issues - manually going offline and online

    For some of us that work on a very large solution with loads of projects, TFS can actually be a pain when it needs to synchronize the solution with the server.

    Hmm... The good news is that you can take TFS offline manually and some of the benefits are as follows: 

    • If you are taking your laptop off the network and want to work offline without waiting for a solution to discover its offline state.
    • Also, the mechanism of having your next attempt to opening a solution to prompt you to take the solution online as opposed to having to manually choosing the Go Online menu option or toolbar button after the solution has opened.

    You can go offline using any of the following:

    ·         Registry Setting:

    Create a *.reg file with the following text in it, and run it before starting Visual Studio.

    Windows Registry Editor Version 5.00

    [HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\TeamFoundation\Servers\SERVERNAME]

    "Offline"=dword:00000001

    "AutoReconnect"=dword:00000000

    ·         Use the ‘tfpt tweakui’ utility

    o    Close Visual Studio

    o    Download and install the latest Team Foundation Power Tools

    o    Start a Visual Studio Command Prompt

    o    Type: tfpt tweakui

    o    Open the server

    o    Check the [X] Server is offline checkbox

    o    Re-open Visual Studio

     

    In addition, when you want to go back online, you can either go to "File | Source Control | Go Online", or delete this registry key.

     

Powered by Community Server (Personal Edition), by Telligent Systems