         CONSTRAINT PK_Project PRIMARY KEY CLUSTERED
     , ProjectName    nvarchar(64)    NOT NULL
         CONSTRAINT UK_Project_ProjectName UNIQUE
+    , SourceUrlBase    nvarchar(256)    NOT NULL
 )
 GO
 CREATE TABLE Build

    SELECT @projectId = ProjectId FROM Project WHERE ProjectName = @ProjectName
    IF @projectId IS NULL
    BEGIN
        INSERT INTO Project (ProjectName) VALUES (@ProjectName)
        
        SET @projectId = @@IDENTITY
    END

        AND SourceRevision = @SourceRevision AND SourceUrl = @SourceUrl
    IF @buildId IS NULL
    BEGIN
        INSERT INTO Build (ProjectId, SourceUrl, SourceRevision)
        VALUES (@projectId, @SourceUrl, @SourceRevision)
        
        SET @buildId = @@IDENTITY
    END
    
    INSERT INTO BuildStep (BuildId, BuildNumber, IsSuccessful, StepName)
    VALUES (@buildId, @BuildNumber, @IsSuccessful, @StepName)
END

GO

EXEC stp_Build_Add
    @ProjectName = 'BuildPipeline'
    , @SourceUrlBase = 'http://aragorn:81/svn/dev/projects/Uncas.BuildPipeline/'
    , @SourceUrl = 'http://aragorn:81/svn/dev/projects/Uncas.BuildPipeline/trunk'
    , @SourceRevision = 952
    , @IsSuccessFul = 1
    , @StepName = 'Unit'
    , @BuildNumber = 3

EXEC stp_Build_Add
    @ProjectName = 'BuildPipeline'
    , @SourceUrlBase = 'http://aragorn:81/svn/dev/projects/Uncas.BuildPipeline/'
    , @SourceUrl = 'http://aragorn:81/svn/dev/projects/Uncas.BuildPipeline/trunk'
    , @SourceRevision = 952
    , @IsSuccessFul = 0
    , @StepName = 'Integration'
    , @BuildNumber = 3

EXEC stp_Build_Add
    @ProjectName = 'BuildPipeline'
    , @SourceUrlBase = 'http://aragorn:81/svn/dev/projects/Uncas.BuildPipeline/'
    , @SourceUrl = 'http://aragorn:81/svn/dev/projects/Uncas.BuildPipeline/trunk'
    , @SourceRevision = 954
    , @IsSuccessFul = 1
    , @StepName = 'Unit'
    , @BuildNumber = 4

EXEC stp_Build_Add
    @ProjectName = 'BuildPipeline'
    , @SourceUrlBase = 'http://aragorn:81/svn/dev/projects/Uncas.BuildPipeline/'
    , @SourceUrl = 'http://aragorn:81/svn/dev/projects/Uncas.BuildPipeline/branches/Experiment1'
    , @SourceRevision = 959
    , @IsSuccessFul = 0
    , @StepName = 'Unit'
    , @BuildNumber = 5
GO

SELECT * FROM Project
SELECT B.BuildId, B.ProjectId, REPLACE(B.SourceUrl, P.SourceUrlBase, '') AS SourceUrlRelative, B.SourceRevision, B.Created, B.Modified
FROM Build AS B
JOIN Project AS P
    ON B.ProjectId = P.ProjectId
SELECT * FROM BuildStep