concept test in category sql

appears as: test, tests, test, tests, The tests, The test
SQL Server MVP Deep Dives Vol. 2

This is an excerpt from Manning's book SQL Server MVP Deep Dives Vol. 2.

If your policy is to apply only an SP and not the CUs, realize that SPs happen less frequently than a CU. There may be an SP released once a year or possibly longer from one SP to another. Because CUs are released every other month, the longer the delta of time between SPs, the more change (and more risk) there is. Even though you wouldn’t be applying them in production, you could be installing the CUs all along in development and/or test environments to see if the fixes impact your applications and address any issues as they arise. That way, by the time the SP is released the amount of work everyone (including the DBAs) would need to do should be fairly trivial. If you don’t do this testing all along, it could mean a lot of work when it comes time to apply the SP. This is especially true if it’s found that there are quite a few fixes you’d need to address. If you’d been taking care of this testing all along, you wouldn’t be in the predicament. You may not have to test every CU, but do so at reasonable intervals (such as every other one).

  • Small and independent— Each test should test only one given scenario at a time, such as a small part of a complex method with some assertions, and tests also should be independent, so the execution order doesn’t influence the tests’ outcome.
  • If your conditions aren’t met, you’ll raise an error to alert that the test has failed so that the developer can work through the problem and correct the issue.

    Listing 4. Basic tests
    DECLARE @ReturnValue INT /************************************************************************** Minimal record **************************************************************************/ EXEC @ReturnValue = dbo.usp_RegisterCustomer @SSN = '999-99-9999' ,@Name = 'Luciano Moreira' ,@DateOfBirth = '1979-12-29' IF NOT EXISTS (SELECT ID FROM dbo.Customer AS C WHERE @ReturnValue = 1 AND C.ID = 1 AND C.Name = 'Luciano Moreira' AND C.SSN = '999-99-9999' AND C.DateOfBirth = '1979-12-29' AND C.MaritalStatus IS NULL AND C.Sex IS NULL AND C.AnnualIncome IS NULL) RAISERROR ( 'ERROR! Problem with the test related to usp_RegisterCustomer' , 16, 1) /************************************************************************** Complete record **************************************************************************/ EXEC @ReturnValue = dbo.usp_RegisterCustomer @SSN = '999-99-9999' ,@Name = 'Bernardo Moreira' ,@DateOfBirth = '2010-10-25' ,@Sex = 'M' ,@MaritalStatus = 'Single' ,@AnnualIncome = 10000 IF NOT EXISTS (SELECT ID FROM dbo.Customer AS C WHERE @ReturnValue = 2 AND C.ID = 2 AND C.Name = 'Bernardo Moreira' AND C.SSN = '999-99-9999' AND C.DateOfBirth = '2010-10-25' AND C.MaritalStatus = 'Single' AND C.Sex = 'M' AND C.AnnualIncome = 10000) RAISERROR ( 'ERROR! Problem with the test related to usp_RegisterCustomer' , 16, 1)
    SQL Server MVP Deep Dives

    This is an excerpt from Manning's book SQL Server MVP Deep Dives.

    This time, the domain expert rejects the example. She tells me that it’s incorrect to have orders for the same customer ID but with different names—same customer ID should always imply same customer name. This leads me to the conclusion that CustomerName is functionally dependent on CustomerID. I already know that both CustomerName and CustomerID depend on OrderNo, which means I can deduct that OrderNo → CustomerName is a transitive dependency. Because third normal form disallows transitive dependencies in a table, I now know that I’ll end up with a separate table for CustomerID and CustomerName, and the latter removed from this table. I can choose to remove the column later and continue testing first (in which case I’ll have a complete set of dependencies when I’m done testing), or I can choose to remove this column now and continue my tests with the remaining attributes only (in which case I must take care not to forget testing the extra table just created, unless all possible dependencies have already been examined). I choose the latter—because the number of tests to perform increases more than linearly with the number of attributes in each table, I prefer to do the tests on several narrow tables rather than on one single wide table.

    Listing 4. Deleting the odd-numbered rows
    --delete the odd rows DELETE FROM Test WHERE col1 % 2 = 1 --view the table SELECT * FROM dbo.Test ;

    Glenn Berry works as a Database Architect at NewsGator Technologies in Denver, Colorado. He is a SQL Server MVP, and he has a whole collection of Microsoft certifications, including MCITP, MCDBA, MCSE, MCSD, MCAD, and MCTS, which proves that he likes to take tests.