api de gestion de ticket, basé sur php-crud-api. Le but est de décorrélé les outils de gestion des données, afin
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

blog.mssql 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. IF (OBJECT_ID('FK_posts_users', 'F') IS NOT NULL)
  2. BEGIN
  3. ALTER TABLE [posts] DROP CONSTRAINT [FK_posts_users]
  4. END
  5. GO
  6. IF (OBJECT_ID('FK_posts_categories', 'F') IS NOT NULL)
  7. BEGIN
  8. ALTER TABLE [posts] DROP CONSTRAINT [FK_posts_categories]
  9. END
  10. GO
  11. IF (OBJECT_ID('FK_post_tags_tags', 'F') IS NOT NULL)
  12. BEGIN
  13. ALTER TABLE [post_tags] DROP CONSTRAINT [FK_post_tags_tags]
  14. END
  15. GO
  16. IF (OBJECT_ID('FK_post_tags_posts', 'F') IS NOT NULL)
  17. BEGIN
  18. ALTER TABLE [post_tags] DROP CONSTRAINT [FK_post_tags_posts]
  19. END
  20. GO
  21. IF (OBJECT_ID('FK_comments_posts', 'F') IS NOT NULL)
  22. BEGIN
  23. ALTER TABLE [comments] DROP CONSTRAINT [FK_comments_posts]
  24. END
  25. GO
  26. IF (OBJECT_ID('users', 'U') IS NOT NULL)
  27. BEGIN
  28. DROP TABLE [users]
  29. END
  30. GO
  31. IF (OBJECT_ID('tags', 'U') IS NOT NULL)
  32. BEGIN
  33. DROP TABLE [tags]
  34. END
  35. GO
  36. IF (OBJECT_ID('posts', 'U') IS NOT NULL)
  37. BEGIN
  38. DROP TABLE [posts]
  39. END
  40. GO
  41. IF (OBJECT_ID('post_tags', 'U') IS NOT NULL)
  42. BEGIN
  43. DROP TABLE [post_tags]
  44. END
  45. GO
  46. IF (OBJECT_ID('comments', 'U') IS NOT NULL)
  47. BEGIN
  48. DROP TABLE [comments]
  49. END
  50. GO
  51. IF (OBJECT_ID('categories', 'U') IS NOT NULL)
  52. BEGIN
  53. DROP TABLE [categories]
  54. END
  55. GO
  56. CREATE TABLE [categories](
  57. [id] [int] IDENTITY,
  58. [name] [nvarchar](max) NOT NULL,
  59. [icon] [varbinary](max) NULL,
  60. PRIMARY KEY CLUSTERED
  61. (
  62. [id] ASC
  63. )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  64. ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
  65. GO
  66. SET ANSI_NULLS ON
  67. GO
  68. SET QUOTED_IDENTIFIER ON
  69. GO
  70. CREATE TABLE [comments](
  71. [id] [int] IDENTITY,
  72. [post_id] [int] NOT NULL,
  73. [message] [nvarchar](max) NOT NULL,
  74. PRIMARY KEY CLUSTERED
  75. (
  76. [id] ASC
  77. )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  78. ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
  79. GO
  80. SET ANSI_NULLS ON
  81. GO
  82. SET QUOTED_IDENTIFIER ON
  83. GO
  84. CREATE TABLE [post_tags](
  85. [id] [int] IDENTITY,
  86. [post_id] [int] NOT NULL,
  87. [tag_id] [int] NOT NULL,
  88. PRIMARY KEY CLUSTERED
  89. (
  90. [id] ASC
  91. )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  92. ) ON [PRIMARY]
  93. GO
  94. SET ANSI_NULLS ON
  95. GO
  96. SET QUOTED_IDENTIFIER ON
  97. GO
  98. CREATE TABLE [posts](
  99. [id] [int] IDENTITY,
  100. [user_id] [int] NOT NULL,
  101. [category_id] [int] NOT NULL,
  102. [content] [nvarchar](max) NOT NULL,
  103. PRIMARY KEY CLUSTERED
  104. (
  105. [id] ASC
  106. )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  107. ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
  108. GO
  109. SET ANSI_NULLS ON
  110. GO
  111. SET QUOTED_IDENTIFIER ON
  112. GO
  113. CREATE TABLE [tags](
  114. [id] [int] IDENTITY,
  115. [name] [nvarchar](max) NOT NULL,
  116. PRIMARY KEY CLUSTERED
  117. (
  118. [id] ASC
  119. )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  120. ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
  121. GO
  122. SET ANSI_NULLS ON
  123. GO
  124. SET QUOTED_IDENTIFIER ON
  125. GO
  126. CREATE TABLE [users](
  127. [id] [int] IDENTITY,
  128. [username] [nvarchar](max) NOT NULL,
  129. [password] [nvarchar](max) NOT NULL,
  130. CONSTRAINT [PK_users] PRIMARY KEY CLUSTERED
  131. (
  132. [id] ASC
  133. )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  134. ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
  135. GO
  136. SET IDENTITY_INSERT [categories] ON
  137. GO
  138. INSERT [categories] ([id], [name], [icon]) VALUES (1, N'anouncement', NULL)
  139. GO
  140. INSERT [categories] ([id], [name], [icon]) VALUES (2, N'article', NULL)
  141. GO
  142. SET IDENTITY_INSERT [categories] OFF
  143. GO
  144. SET IDENTITY_INSERT [comments] ON
  145. GO
  146. INSERT [comments] ([id], [post_id], [message]) VALUES (1, 1, N'great')
  147. GO
  148. INSERT [comments] ([id], [post_id], [message]) VALUES (2, 1, N'fantastic')
  149. GO
  150. INSERT [comments] ([id], [post_id], [message]) VALUES (3, 2, N'thank you')
  151. GO
  152. INSERT [comments] ([id], [post_id], [message]) VALUES (4, 2, N'awesome')
  153. GO
  154. SET IDENTITY_INSERT [comments] OFF
  155. GO
  156. SET IDENTITY_INSERT [post_tags] ON
  157. GO
  158. INSERT [post_tags] ([id], [post_id], [tag_id]) VALUES (1, 1, 1)
  159. GO
  160. INSERT [post_tags] ([id], [post_id], [tag_id]) VALUES (2, 1, 2)
  161. GO
  162. INSERT [post_tags] ([id], [post_id], [tag_id]) VALUES (3, 2, 1)
  163. GO
  164. INSERT [post_tags] ([id], [post_id], [tag_id]) VALUES (4, 2, 2)
  165. GO
  166. SET IDENTITY_INSERT [post_tags] OFF
  167. GO
  168. SET IDENTITY_INSERT [posts] ON
  169. GO
  170. INSERT [posts] ([id], [user_id], [category_id], [content]) VALUES (1, 1, 1, N'blog started')
  171. GO
  172. INSERT [posts] ([id], [user_id], [category_id], [content]) VALUES (2, 1, 2, N'It works!')
  173. GO
  174. SET IDENTITY_INSERT [posts] OFF
  175. GO
  176. SET IDENTITY_INSERT [tags] ON
  177. GO
  178. INSERT [tags] ([id], [name]) VALUES (1, N'funny')
  179. GO
  180. INSERT [tags] ([id], [name]) VALUES (2, N'important')
  181. GO
  182. SET IDENTITY_INSERT [tags] OFF
  183. GO
  184. SET IDENTITY_INSERT [users] ON
  185. GO
  186. INSERT [users] ([id], [username], [password]) VALUES (1, N'user1', N'pass1')
  187. GO
  188. INSERT [users] ([id], [username], [password]) VALUES (2, N'user2', N'pass2')
  189. GO
  190. SET IDENTITY_INSERT [users] OFF
  191. GO
  192. ALTER TABLE [comments] WITH CHECK ADD CONSTRAINT [FK_comments_posts] FOREIGN KEY([post_id])
  193. REFERENCES [posts] ([id])
  194. GO
  195. ALTER TABLE [comments] CHECK CONSTRAINT [FK_comments_posts]
  196. GO
  197. ALTER TABLE [post_tags] WITH CHECK ADD CONSTRAINT [FK_post_tags_posts] FOREIGN KEY([post_id])
  198. REFERENCES [posts] ([id])
  199. GO
  200. ALTER TABLE [post_tags] CHECK CONSTRAINT [FK_post_tags_posts]
  201. GO
  202. ALTER TABLE [post_tags] WITH CHECK ADD CONSTRAINT [FK_post_tags_tags] FOREIGN KEY([tag_id])
  203. REFERENCES [tags] ([id])
  204. GO
  205. ALTER TABLE [post_tags] CHECK CONSTRAINT [FK_post_tags_tags]
  206. GO
  207. ALTER TABLE [posts] WITH CHECK ADD CONSTRAINT [FK_posts_categories] FOREIGN KEY([category_id])
  208. REFERENCES [categories] ([id])
  209. GO
  210. ALTER TABLE [posts] CHECK CONSTRAINT [FK_posts_categories]
  211. GO
  212. ALTER TABLE [posts] WITH CHECK ADD CONSTRAINT [FK_posts_users] FOREIGN KEY([user_id])
  213. REFERENCES [users] ([id])
  214. GO
  215. ALTER TABLE [posts] CHECK CONSTRAINT [FK_posts_users]
  216. GO