Category: Blog

  • SQLInspire

    I’m off to New York City, center of the universe, and SQLInspire today. This is my last trip of the year, and I am very glad for that. This will be my 15th event of the year and that’s a lot. I’m looking forward to a run in Central Park, however, and seeing the bright lights and big city for a day.

    This is one event, however, that I’m very much looking forward to. The SQLPeople people, Andy Leonard (blog | @AndyLeonard)  and Brian Moran (Linchpin People | @briancmoran), put together this event based on the TED events that occur all over the world. I love TED talks, and find myself learning some amazing things from them. This event is more SQL focused, but designed in the same way. To bring new ideas to you, inspire you, and get you to think about the world around you.

    My session is Finding Your Balance, and I’m hoping to goes over well. I’ll post a transcript of the talk after the event. If you attend, please come by and shake my hand.

  • Quite a salary

    If this article is true, and I suspect it is for some software engineers, why aren’t more people learning programming?

    I think that we have a few problems in the industry, and I have an editorial coming out soon on this. One is that this type of money is rare. So many people work for companies and they make a good living, but they work hard. We have a perception issue of this industry being geeky, long hours, not a lot of respect, etc. I hear so many complaints from people that it’s hard sometimes to decide if they really like their jobs or they’re stuck in them, much like I hear complaints from people in accounting, or sales, etc.

    The other issue is that we haven’t done a great job of getting younger people interested in computers. We require more computer work in schools, and my kids use computers as much as I did when I was 12 and a geek, but they’re using computers as tools to produce an end product, not as a way to build another tool.

    We need to advocate, interest, and excite more kids about technology as a career if we want it to grow.

  • A view has no data

    I have seen quite a few posts and questions lately from people that are trying to change the data in a view, or move data in a view.

    A view has no data.

    It’s that simple. If you have something like this in AdventureWorks:

    SELECT firstname
    , lastname
     FROM HumanResources.vEmployee
     

    And this view is defined as:

    CREATE VIEW [HumanResources].[vEmployee] 
    AS 
    SELECT 
    e.[EmployeeID]
    ,c.[Title]
    ,c.[FirstName]
    ,c.[MiddleName]
    ,c.[LastName]
    ,c.[Suffix]
    ,e.[Title] AS [JobTitle] 
    ,c.[Phone]
    ,c.[EmailAddress]
    ,c.[EmailPromotion]
    ,a.[AddressLine1]
    ,a.[AddressLine2]
    ,a.[City]
    ,sp.[Name] AS [StateProvinceName] 
    ,a.[PostalCode]
    ,cr.[Name] AS [CountryRegionName] 
    ,c.[AdditionalContactInfo]
    FROM [HumanResources].[Employee] e
    INNER JOIN [Person].[Contact] c 
    ON c.[ContactID] = e.[ContactID]
    INNER JOIN [HumanResources].[EmployeeAddress] ea 
    ON e.[EmployeeID] = ea.[EmployeeID] 
    INNER JOIN [Person].[Address] a 
    ON ea.[AddressID] = a.[AddressID]
    INNER JOIN [Person].[StateProvince] sp 
    ON sp.[StateProvinceID] = a.[StateProvinceID]
    INNER JOIN [Person].[CountryRegion] cr 
    ON cr.[CountryRegionCode] = sp.[CountryRegionCode];

    The SELECT statement is the same as running

     SELECT 
     c.[FirstName]
    ,c.[LastName]
    FROM [HumanResources].[Employee] e
    INNER JOIN [Person].[Contact] c 
    ON c.[ContactID] = e.[ContactID]
    INNER JOIN [HumanResources].[EmployeeAddress] ea 
    ON e.[EmployeeID] = ea.[EmployeeID] 
    INNER JOIN [Person].[Address] a 
    ON ea.[AddressID] = a.[AddressID]
    INNER JOIN [Person].[StateProvince] sp 
    ON sp.[StateProvinceID] = a.[StateProvinceID]
    INNER JOIN [Person].[CountryRegion] cr 
    ON cr.[CountryRegionCode] = sp.[CountryRegionCode];
    

    Note this is exactly the same thing as the view definition with fewer columns included. Or it could be written like this:

    SELECT firstname
    , lastname
     FROM 
     (
    SELECT 
    e.[EmployeeID]
    ,c.[Title]
    ,c.[FirstName]
    ,c.[MiddleName]
    ,c.[LastName]
    ,c.[Suffix]
    ,e.[Title] AS [JobTitle] 
    ,c.[Phone]
    ,c.[EmailAddress]
    ,c.[EmailPromotion]
    ,a.[AddressLine1]
    ,a.[AddressLine2]
    ,a.[City]
    ,sp.[Name] AS [StateProvinceName] 
    ,a.[PostalCode]
    ,cr.[Name] AS [CountryRegionName] 
    ,c.[AdditionalContactInfo]
    FROM [HumanResources].[Employee] e
    INNER JOIN [Person].[Contact] c 
    ON c.[ContactID] = e.[ContactID]
    INNER JOIN [HumanResources].[EmployeeAddress] ea 
    ON e.[EmployeeID] = ea.[EmployeeID] 
    INNER JOIN [Person].[Address] a 
    ON ea.[AddressID] = a.[AddressID]
    INNER JOIN [Person].[StateProvince] sp 
    ON sp.[StateProvinceID] = a.[StateProvinceID]
    INNER JOIN [Person].[CountryRegion] cr 
    ON cr.[CountryRegionCode] = sp.[CountryRegionCode]
     ) a
     

    In this case I’ve moved the view definition into the FROM clause of my SELECT query.

    A view is literally a stored query that you can use to make it easier to write code. There is no data in the view, so if you need to change the data, or “refresh” the data from another database, you need to move the data in the tables that are referenced in the VIEW.

  • Filestream and Backups

    What happens when you backup a filestream enabled database in SQL Server 2008? According to BOL, your data is backed up as part of the normal backup process.

    Does it work? Let’s do a little test. I made a simple AdventureWorks2008 backup like this:

    backup database AdventureWorks2008 to disk = c:\sqlbackup\ADW2K8test.bak’

    That gave me a single file, 222MB in size. This includes the filestream data, which by default is located in the \Documents folder below your default data folder in SQL Server 2008.

    filestream

    I can create two new folders. I created a “test” folder below my data directory on the test machine, and then a “FilestreamDocs” folder below that.

    filestream2 

    I then issued this restore:

    RESTORE DATABASE [ADW2k8Test] 
     FROM  DISK = N'C:\SQLBackup\adw2008.bak' 
     WITH  FILE = 1,  
     MOVE N'AdventureWorks2008_Data' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\test\adw2008.mdf',
     MOVE N'AdventureWorks2008_Log' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\test\adw2k8.ldf',  
     MOVE N'FileStreamDocuments' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\test\filestreamdocs',  
     NOUNLOAD,  REPLACE,  STATS = 10
    GO
    

    That completed, and I had a fully functional database that included my filestream data.