Advertisement
anchormodeling

Using the insert/update/delete triggers

Dec 11th, 2011
518
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 1.04 KB | None | 0 0
  1. -- two gender values
  2. insert into GEN_Gender values (0, 'Male');
  3. insert into GEN_Gender values (1, 'Female');
  4.  
  5. -- create an actor (automatically generated id)
  6. insert into lAC_Actor (
  7.     AC_NAM_Actor_Name,
  8.     AC_NAM_ChangedAt,
  9.     GEN_Gender
  10. )
  11. values('Rönnbäck', '1972-08-20', 'Male');
  12.  
  13. -- update that actor (using the generated id)
  14. update lAC_Actor
  15. set
  16.     AC_NAM_Actor_Name = 'Samuelsson'
  17. where
  18.     AC_ID = 1;
  19.  
  20. -- no table elimination
  21. select * from lAC_Actor;
  22. select * from pAC_Actor('1999-12-31');
  23.  
  24. -- table elimination (left joins, attributes eliminated)
  25. select AC_NAM_Actor_Name from lAC_Actor;
  26. select AC_NAM_Actor_Name from pAC_Actor('1999-12-31');
  27.  
  28. -- table elimination (foreign keys, also anchor eliminated)
  29. select AC_NAM_Actor_Name from lAC_Actor where AC_NAM_Actor_Name is not null;
  30. select AC_NAM_Actor_Name from pAC_Actor('1999-12-31') where AC_NAM_Actor_Name is not null;
  31.  
  32. -- remove rows
  33. delete from lAC_Actor where AC_ID = 1;
  34.  
  35. -- now underlying tables are empty
  36. select AC_ID from AC_Actor;
  37. select AC_ID from AC_NAM_Actor_Name;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement