EDM.edmx.sql 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. -- --------------------------------------------------
  2. -- Entity Designer DDL Script for SQL Server 2005, 2008, 2012 and Azure
  3. -- --------------------------------------------------
  4. -- Date Created: 08/12/2022 17:57:11
  5. -- Generated from EDMX file: C:\Users\milic\source\repos\MyTests\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. [CanAgain] bit NOT NULL
  71. );
  72. GO
  73. -- Creating table 'Users'
  74. CREATE TABLE [dbo].[Users] (
  75. [IdUser] int NOT NULL,
  76. [Login] nvarchar(50) NOT NULL,
  77. [Password] nvarchar(50) NOT NULL,
  78. [Email] nvarchar(50) NOT NULL,
  79. [Info] nvarchar(50) NULL,
  80. [Image] varbinary(max) NULL,
  81. [Post] nvarchar(25) NOT NULL,
  82. [Surname] nvarchar(50) NOT NULL,
  83. [Name] nvarchar(50) NOT NULL,
  84. [Patronymic] nvarchar(50) NOT NULL
  85. );
  86. GO
  87. -- --------------------------------------------------
  88. -- Creating all PRIMARY KEY constraints
  89. -- --------------------------------------------------
  90. -- Creating primary key on [IdUserAnswer] in table 'Answers'
  91. ALTER TABLE [dbo].[Answers]
  92. ADD CONSTRAINT [PK_Answers]
  93. PRIMARY KEY CLUSTERED ([IdUserAnswer] ASC);
  94. GO
  95. -- Creating primary key on [IdQuestion] in table 'Questions'
  96. ALTER TABLE [dbo].[Questions]
  97. ADD CONSTRAINT [PK_Questions]
  98. PRIMARY KEY CLUSTERED ([IdQuestion] ASC);
  99. GO
  100. -- Creating primary key on [IdTest] in table 'Tests'
  101. ALTER TABLE [dbo].[Tests]
  102. ADD CONSTRAINT [PK_Tests]
  103. PRIMARY KEY CLUSTERED ([IdTest] ASC);
  104. GO
  105. -- Creating primary key on [IdUser] in table 'Users'
  106. ALTER TABLE [dbo].[Users]
  107. ADD CONSTRAINT [PK_Users]
  108. PRIMARY KEY CLUSTERED ([IdUser] ASC);
  109. GO
  110. -- --------------------------------------------------
  111. -- Creating all FOREIGN KEY constraints
  112. -- --------------------------------------------------
  113. -- Creating foreign key on [IdQuestion] in table 'Answers'
  114. ALTER TABLE [dbo].[Answers]
  115. ADD CONSTRAINT [FK_Answers_Questions]
  116. FOREIGN KEY ([IdQuestion])
  117. REFERENCES [dbo].[Questions]
  118. ([IdQuestion])
  119. ON DELETE NO ACTION ON UPDATE NO ACTION;
  120. GO
  121. -- Creating non-clustered index for FOREIGN KEY 'FK_Answers_Questions'
  122. CREATE INDEX [IX_FK_Answers_Questions]
  123. ON [dbo].[Answers]
  124. ([IdQuestion]);
  125. GO
  126. -- Creating foreign key on [IdUser] in table 'Answers'
  127. ALTER TABLE [dbo].[Answers]
  128. ADD CONSTRAINT [FK_Answers_Users]
  129. FOREIGN KEY ([IdUser])
  130. REFERENCES [dbo].[Users]
  131. ([IdUser])
  132. ON DELETE NO ACTION ON UPDATE NO ACTION;
  133. GO
  134. -- Creating non-clustered index for FOREIGN KEY 'FK_Answers_Users'
  135. CREATE INDEX [IX_FK_Answers_Users]
  136. ON [dbo].[Answers]
  137. ([IdUser]);
  138. GO
  139. -- Creating foreign key on [IdTest] in table 'Questions'
  140. ALTER TABLE [dbo].[Questions]
  141. ADD CONSTRAINT [FK_Questions_Tests]
  142. FOREIGN KEY ([IdTest])
  143. REFERENCES [dbo].[Tests]
  144. ([IdTest])
  145. ON DELETE NO ACTION ON UPDATE NO ACTION;
  146. GO
  147. -- Creating non-clustered index for FOREIGN KEY 'FK_Questions_Tests'
  148. CREATE INDEX [IX_FK_Questions_Tests]
  149. ON [dbo].[Questions]
  150. ([IdTest]);
  151. GO
  152. -- Creating foreign key on [IdUser] in table 'Tests'
  153. ALTER TABLE [dbo].[Tests]
  154. ADD CONSTRAINT [FK_Tests_Users]
  155. FOREIGN KEY ([IdUser])
  156. REFERENCES [dbo].[Users]
  157. ([IdUser])
  158. ON DELETE NO ACTION ON UPDATE NO ACTION;
  159. GO
  160. -- Creating non-clustered index for FOREIGN KEY 'FK_Tests_Users'
  161. CREATE INDEX [IX_FK_Tests_Users]
  162. ON [dbo].[Tests]
  163. ([IdUser]);
  164. GO
  165. -- --------------------------------------------------
  166. -- Script has ended
  167. -- --------------------------------------------------