EDM.edmx.sql 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. -- --------------------------------------------------
  2. -- Entity Designer DDL Script for SQL Server 2005, 2008, 2012 and Azure
  3. -- --------------------------------------------------
  4. -- Date Created: 08/09/2022 06:03:40
  5. -- Generated from EDMX file: C:\Users\pc\source\repos\StTest\MyTests\EDM.edmx
  6. -- --------------------------------------------------
  7. SET QUOTED_IDENTIFIER OFF;
  8. GO
  9. USE [MyTestsDataBase];
  10. GO
  11. IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
  12. GO
  13. -- --------------------------------------------------
  14. -- Dropping existing FOREIGN KEY constraints
  15. -- --------------------------------------------------
  16. IF OBJECT_ID(N'[dbo].[FK_Answers_Questions]', 'F') IS NOT NULL
  17. ALTER TABLE [dbo].[Answers] DROP CONSTRAINT [FK_Answers_Questions];
  18. GO
  19. IF OBJECT_ID(N'[dbo].[FK_Answers_Users]', 'F') IS NOT NULL
  20. ALTER TABLE [dbo].[Answers] DROP CONSTRAINT [FK_Answers_Users];
  21. GO
  22. IF OBJECT_ID(N'[dbo].[FK_Questions_Tests]', 'F') IS NOT NULL
  23. ALTER TABLE [dbo].[Questions] DROP CONSTRAINT [FK_Questions_Tests];
  24. GO
  25. IF OBJECT_ID(N'[dbo].[FK_Tests_Users]', 'F') IS NOT NULL
  26. ALTER TABLE [dbo].[Tests] DROP CONSTRAINT [FK_Tests_Users];
  27. GO
  28. -- --------------------------------------------------
  29. -- Dropping existing tables
  30. -- --------------------------------------------------
  31. IF OBJECT_ID(N'[dbo].[Answers]', 'U') IS NOT NULL
  32. DROP TABLE [dbo].[Answers];
  33. GO
  34. IF OBJECT_ID(N'[dbo].[Questions]', 'U') IS NOT NULL
  35. DROP TABLE [dbo].[Questions];
  36. GO
  37. IF OBJECT_ID(N'[dbo].[Tests]', 'U') IS NOT NULL
  38. DROP TABLE [dbo].[Tests];
  39. GO
  40. IF OBJECT_ID(N'[dbo].[Users]', 'U') IS NOT NULL
  41. DROP TABLE [dbo].[Users];
  42. GO
  43. -- --------------------------------------------------
  44. -- Creating all tables
  45. -- --------------------------------------------------
  46. -- Creating table 'Answers'
  47. CREATE TABLE [dbo].[Answers] (
  48. [IdUserAnswer] int NOT NULL,
  49. [IdQuestion] int NOT NULL,
  50. [IdUser] int NOT NULL,
  51. [Answer] nvarchar(150) NOT NULL
  52. );
  53. GO
  54. -- Creating table 'Questions'
  55. CREATE TABLE [dbo].[Questions] (
  56. [IdQuestion] int NOT NULL,
  57. [IdTest] int NOT NULL,
  58. [Content] nvarchar(150) NOT NULL,
  59. [Answer] nvarchar(150) NOT NULL
  60. );
  61. GO
  62. -- Creating table 'Tests'
  63. CREATE TABLE [dbo].[Tests] (
  64. [IdTest] int NOT NULL,
  65. [IdUser] int NOT NULL,
  66. [Name] nvarchar(150) NOT NULL,
  67. [Image] varbinary(max) NULL,
  68. [IsAnswersVisible] bit NOT NULL,
  69. [IsVisible] bit NOT NULL
  70. );
  71. GO
  72. -- Creating table 'Users'
  73. CREATE TABLE [dbo].[Users] (
  74. [IdUser] int NOT NULL,
  75. [Login] nvarchar(50) NOT NULL,
  76. [Password] nvarchar(50) NOT NULL,
  77. [Email] nvarchar(50) NOT NULL,
  78. [Info] nvarchar(50) NULL,
  79. [Image] varbinary(max) NULL,
  80. [Post] nvarchar(25) NOT NULL,
  81. [Surname] nvarchar(50) NOT NULL,
  82. [Name] nvarchar(50) NOT NULL,
  83. [Patronymic] nvarchar(50) NOT NULL
  84. );
  85. GO
  86. -- --------------------------------------------------
  87. -- Creating all PRIMARY KEY constraints
  88. -- --------------------------------------------------
  89. -- Creating primary key on [IdUserAnswer] in table 'Answers'
  90. ALTER TABLE [dbo].[Answers]
  91. ADD CONSTRAINT [PK_Answers]
  92. PRIMARY KEY CLUSTERED ([IdUserAnswer] ASC);
  93. GO
  94. -- Creating primary key on [IdQuestion] in table 'Questions'
  95. ALTER TABLE [dbo].[Questions]
  96. ADD CONSTRAINT [PK_Questions]
  97. PRIMARY KEY CLUSTERED ([IdQuestion] ASC);
  98. GO
  99. -- Creating primary key on [IdTest] in table 'Tests'
  100. ALTER TABLE [dbo].[Tests]
  101. ADD CONSTRAINT [PK_Tests]
  102. PRIMARY KEY CLUSTERED ([IdTest] ASC);
  103. GO
  104. -- Creating primary key on [IdUser] in table 'Users'
  105. ALTER TABLE [dbo].[Users]
  106. ADD CONSTRAINT [PK_Users]
  107. PRIMARY KEY CLUSTERED ([IdUser] ASC);
  108. GO
  109. -- --------------------------------------------------
  110. -- Creating all FOREIGN KEY constraints
  111. -- --------------------------------------------------
  112. -- Creating foreign key on [IdQuestion] in table 'Answers'
  113. ALTER TABLE [dbo].[Answers]
  114. ADD CONSTRAINT [FK_Answers_Questions]
  115. FOREIGN KEY ([IdQuestion])
  116. REFERENCES [dbo].[Questions]
  117. ([IdQuestion])
  118. ON DELETE NO ACTION ON UPDATE NO ACTION;
  119. GO
  120. -- Creating non-clustered index for FOREIGN KEY 'FK_Answers_Questions'
  121. CREATE INDEX [IX_FK_Answers_Questions]
  122. ON [dbo].[Answers]
  123. ([IdQuestion]);
  124. GO
  125. -- Creating foreign key on [IdUser] in table 'Answers'
  126. ALTER TABLE [dbo].[Answers]
  127. ADD CONSTRAINT [FK_Answers_Users]
  128. FOREIGN KEY ([IdUser])
  129. REFERENCES [dbo].[Users]
  130. ([IdUser])
  131. ON DELETE NO ACTION ON UPDATE NO ACTION;
  132. GO
  133. -- Creating non-clustered index for FOREIGN KEY 'FK_Answers_Users'
  134. CREATE INDEX [IX_FK_Answers_Users]
  135. ON [dbo].[Answers]
  136. ([IdUser]);
  137. GO
  138. -- Creating foreign key on [IdTest] in table 'Questions'
  139. ALTER TABLE [dbo].[Questions]
  140. ADD CONSTRAINT [FK_Questions_Tests]
  141. FOREIGN KEY ([IdTest])
  142. REFERENCES [dbo].[Tests]
  143. ([IdTest])
  144. ON DELETE NO ACTION ON UPDATE NO ACTION;
  145. GO
  146. -- Creating non-clustered index for FOREIGN KEY 'FK_Questions_Tests'
  147. CREATE INDEX [IX_FK_Questions_Tests]
  148. ON [dbo].[Questions]
  149. ([IdTest]);
  150. GO
  151. -- Creating foreign key on [IdUser] in table 'Tests'
  152. ALTER TABLE [dbo].[Tests]
  153. ADD CONSTRAINT [FK_Tests_Users]
  154. FOREIGN KEY ([IdUser])
  155. REFERENCES [dbo].[Users]
  156. ([IdUser])
  157. ON DELETE NO ACTION ON UPDATE NO ACTION;
  158. GO
  159. -- Creating non-clustered index for FOREIGN KEY 'FK_Tests_Users'
  160. CREATE INDEX [IX_FK_Tests_Users]
  161. ON [dbo].[Tests]
  162. ([IdUser]);
  163. GO
  164. -- --------------------------------------------------
  165. -- Script has ended
  166. -- --------------------------------------------------