Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. use lab4;
  2.  
  3. create table team (
  4. id uniqueidentifier default newid() primary key,
  5. city nvarchar(1000) not null,
  6. team_name nvarchar(max) not null
  7. );
  8.  
  9. create table match (
  10. id uniqueidentifier default newid() primary key,
  11. name nvarchar(1000) not null,
  12. city nvarchar(1000) not null,
  13. team uniqueidentifier not null,
  14. constraint fk_match_team foreign key (team) references team(id)
  15. on update no action
  16. on delete no action
  17. );
  18.  
  19. create table player (
  20. id uniqueidentifier default newid() primary key,
  21. name nvarchar(max) not null,
  22. team uniqueidentifier not null,
  23. constraint fk_player_team foreign key (team) references team(id)
  24. on update no action
  25. on delete no action
  26. );
  27.  
  28. go
  29.  
  30. set implicit_transactions off;
  31. set implicit_transactions on;
  32. select @@TRANCOUNT;
  33.  
  34. insert into team(city, team_name) values ('Moscow', 'Team1');
  35. insert into team(city, team_name) values ('Paris', 'Team2');
  36. insert into team(city, team_name) values ('New York', 'Team3');
  37. delete from team;
  38. select * from team;
  39. BEGIN TRAN;
  40. COMMIT;
  41. ROLLBACK;
  42.  
  43. go
  44.  
  45. SELECT @@TRANCOUNT;
  46. BEGIN TRAN;
  47. SELECT @@TRANCOUNT;
  48. INSERT INTO team(city, team_name) VALUES('Moscow', 'Team4');
  49. SELECT @@TRANCOUNT;
  50. BEGIN TRAN;
  51. SELECT @@TRANCOUNT; -- = 2
  52. -- Просмотрите добавленную строку
  53. SELECT * FROM team;
  54. COMMIT
  55. SELECT @@TRANCOUNT; -- = 1
  56. -- ВЫВЕДИТЕ СПИСОК АКТИВНЫХ ТРАНЗАКЦИЙ
  57. COMMIT TRAN;
  58. -- Удалите добавленную строку
  59. DELETE FROM team;
  60. select * from team;
  61.  
  62. SELECT * FROM sys.dm_tran_active_transactions
  63.  
  64. go
  65.  
  66. SELECT @@TRANCOUNT;
  67. BEGIN TRAN;
  68. SELECT @@TRANCOUNT;
  69. INSERT INTO team(city, team_name) VALUES('Moscow', 'Team5');
  70. BEGIN TRAN;
  71. SELECT @@TRANCOUNT;
  72. INSERT INTO team(city, team_name) VALUES('Paris', 'Team6');
  73. ROLLBACK;
  74. SELECT @@TRANCOUNT;
  75. -- Просмотрите добавленные строки
  76. SELECT * FROM team;
  77. delete from team;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement