Lektion 2: lösningsförslag

  1. -- 1.1
  2. UPDATE Customer
  3. SET CreditLimit = CreditLimit + 500
  4. -- 1.2
  5. UPDATE Customer
  6. SET CreditLimit = CreditLimit + 500
  7. WHERE State = 'CA'
  8. -- 1.3
  9. DELETE FROM Customer
  10. WHERE State = 'OR' OR State = 'UT'
  11. -- 2.1
  12. -- Exempel på lämpligt constraint:
  13. Category IN ('computer', 'telephone', 'TV')
  14. -- 2.2
  15. UPDATE Product
  16. SET Price = Price - 50
  17. -- 2.3
  18. UPDATE Product
  19. SET Price = Price * 0.8
  20. -- 2.4
  21. -- Lösningen till 2.3 behöver inte ändras.
  22. -- Lösningen till 2.2 kan göras på ett simpelt men begränsat sätt:
  23. UPDATE Product
  24. SET Price = Price - 50
  25. WHERE Price >= 50
  26. -- Alternativt på ett mer användbart sätt med två kommandon:
  27. UPDATE Product
  28. SET Price = Price - 50
  29. WHERE Price >= 50
  30. UPDATE Product
  31. SET Price = 0
  32. WHERE Price < 50
  33. -- Det kan också lösas med mer avancerade delar av T-SQL, som CASE och IIF.
  34. -- 3
  35. INSERT INTO Production.Product (Name, ProductNumber, SafetyStockLevel, ReorderPoint, StandardCost, ListPrice, DaysToManufacture, SellStartDate)
  36. VALUES ('Test Product', 'TEST123', 100, 200, 300, 400, 5, '2010-01-01')