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
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

blog_sqlserver.sql 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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('products', 'U') IS NOT NULL)
  27. BEGIN
  28. DROP TABLE [products]
  29. END
  30. GO
  31. IF (OBJECT_ID('events', 'U') IS NOT NULL)
  32. BEGIN
  33. DROP TABLE [events]
  34. END
  35. GO
  36. IF (OBJECT_ID('countries', 'U') IS NOT NULL)
  37. BEGIN
  38. DROP TABLE [countries]
  39. END
  40. GO
  41. IF (OBJECT_ID('users', 'U') IS NOT NULL)
  42. BEGIN
  43. DROP TABLE [users]
  44. END
  45. GO
  46. IF (OBJECT_ID('tags', 'U') IS NOT NULL)
  47. BEGIN
  48. DROP TABLE [tags]
  49. END
  50. GO
  51. IF (OBJECT_ID('posts', 'U') IS NOT NULL)
  52. BEGIN
  53. DROP TABLE [posts]
  54. END
  55. GO
  56. IF (OBJECT_ID('post_tags', 'U') IS NOT NULL)
  57. BEGIN
  58. DROP TABLE [post_tags]
  59. END
  60. GO
  61. IF (OBJECT_ID('comments', 'U') IS NOT NULL)
  62. BEGIN
  63. DROP TABLE [comments]
  64. END
  65. GO
  66. IF (OBJECT_ID('categories', 'U') IS NOT NULL)
  67. BEGIN
  68. DROP TABLE [categories]
  69. END
  70. GO
  71. IF (OBJECT_ID('tag_usage', 'V') IS NOT NULL)
  72. BEGIN
  73. DROP VIEW [tag_usage]
  74. END
  75. GO
  76. CREATE TABLE [categories](
  77. [id] [int] IDENTITY,
  78. [name] [nvarchar](max) NOT NULL,
  79. [icon] [varbinary](max) NULL,
  80. PRIMARY KEY CLUSTERED
  81. (
  82. [id] ASC
  83. )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  84. ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
  85. GO
  86. SET ANSI_NULLS ON
  87. GO
  88. SET QUOTED_IDENTIFIER ON
  89. GO
  90. CREATE TABLE [comments](
  91. [id] [int] IDENTITY,
  92. [post_id] [int] NOT NULL,
  93. [message] [nvarchar](max) NOT NULL,
  94. PRIMARY KEY CLUSTERED
  95. (
  96. [id] ASC
  97. )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  98. ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
  99. GO
  100. SET ANSI_NULLS ON
  101. GO
  102. SET QUOTED_IDENTIFIER ON
  103. GO
  104. CREATE TABLE [post_tags](
  105. [id] [int] IDENTITY,
  106. [post_id] [int] NOT NULL,
  107. [tag_id] [int] NOT NULL,
  108. PRIMARY KEY CLUSTERED
  109. (
  110. [id] ASC
  111. )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  112. ) ON [PRIMARY]
  113. GO
  114. SET ANSI_NULLS ON
  115. GO
  116. SET QUOTED_IDENTIFIER ON
  117. GO
  118. CREATE TABLE [posts](
  119. [id] [int] IDENTITY,
  120. [user_id] [int] NOT NULL,
  121. [category_id] [int] NOT NULL,
  122. [content] [nvarchar](max) NOT NULL,
  123. PRIMARY KEY CLUSTERED
  124. (
  125. [id] ASC
  126. )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  127. ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
  128. GO
  129. SET ANSI_NULLS ON
  130. GO
  131. SET QUOTED_IDENTIFIER ON
  132. GO
  133. CREATE TABLE [tags](
  134. [id] [int] IDENTITY,
  135. [name] [nvarchar](max) NOT NULL,
  136. PRIMARY KEY CLUSTERED
  137. (
  138. [id] ASC
  139. )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  140. ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
  141. GO
  142. SET ANSI_NULLS ON
  143. GO
  144. SET QUOTED_IDENTIFIER ON
  145. GO
  146. CREATE TABLE [users](
  147. [id] [int] IDENTITY,
  148. [username] [nvarchar](max) NOT NULL,
  149. [password] [nvarchar](max) NOT NULL,
  150. [location] [geometry] NULL,
  151. CONSTRAINT [PK_users] PRIMARY KEY CLUSTERED
  152. (
  153. [id] ASC
  154. )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  155. ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
  156. GO
  157. SET ANSI_NULLS ON
  158. GO
  159. SET QUOTED_IDENTIFIER ON
  160. GO
  161. CREATE TABLE [countries](
  162. [id] [int] IDENTITY,
  163. [name] [nvarchar](max) NOT NULL,
  164. [shape] [geometry] NOT NULL,
  165. CONSTRAINT [PK_countries] PRIMARY KEY CLUSTERED
  166. (
  167. [id] ASC
  168. )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  169. ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
  170. GO
  171. SET ANSI_NULLS ON
  172. GO
  173. SET QUOTED_IDENTIFIER ON
  174. GO
  175. CREATE TABLE [events](
  176. [id] [int] IDENTITY,
  177. [name] [nvarchar](max) NOT NULL,
  178. [datetime] [datetime2](3) NOT NULL,
  179. CONSTRAINT [PK_events] PRIMARY KEY CLUSTERED
  180. (
  181. [id] ASC
  182. )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  183. ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
  184. GO
  185. SET ANSI_NULLS ON
  186. GO
  187. SET QUOTED_IDENTIFIER ON
  188. GO
  189. CREATE VIEW [tag_usage]
  190. AS
  191. SELECT top 100 PERCENT name, COUNT(name) AS [count] FROM tags, post_tags WHERE tags.id = post_tags.tag_id GROUP BY name ORDER BY [count] DESC, name
  192. GO
  193. SET ANSI_NULLS ON
  194. GO
  195. SET QUOTED_IDENTIFIER ON
  196. GO
  197. CREATE TABLE [products](
  198. [id] [int] IDENTITY,
  199. [name] [nvarchar](max) NOT NULL,
  200. [price] [decimal](10,2) NOT NULL,
  201. CONSTRAINT [PK_products] PRIMARY KEY CLUSTERED
  202. (
  203. [id] ASC
  204. )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  205. ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
  206. GO
  207. SET IDENTITY_INSERT [categories] ON
  208. GO
  209. INSERT [categories] ([id], [name], [icon]) VALUES (1, N'announcement', NULL)
  210. GO
  211. INSERT [categories] ([id], [name], [icon]) VALUES (2, N'article', NULL)
  212. GO
  213. SET IDENTITY_INSERT [categories] OFF
  214. GO
  215. SET IDENTITY_INSERT [comments] ON
  216. GO
  217. INSERT [comments] ([id], [post_id], [message]) VALUES (1, 1, N'great')
  218. GO
  219. INSERT [comments] ([id], [post_id], [message]) VALUES (2, 1, N'fantastic')
  220. GO
  221. INSERT [comments] ([id], [post_id], [message]) VALUES (3, 2, N'thank you')
  222. GO
  223. INSERT [comments] ([id], [post_id], [message]) VALUES (4, 2, N'awesome')
  224. GO
  225. SET IDENTITY_INSERT [comments] OFF
  226. GO
  227. SET IDENTITY_INSERT [post_tags] ON
  228. GO
  229. INSERT [post_tags] ([id], [post_id], [tag_id]) VALUES (1, 1, 1)
  230. GO
  231. INSERT [post_tags] ([id], [post_id], [tag_id]) VALUES (2, 1, 2)
  232. GO
  233. INSERT [post_tags] ([id], [post_id], [tag_id]) VALUES (3, 2, 1)
  234. GO
  235. INSERT [post_tags] ([id], [post_id], [tag_id]) VALUES (4, 2, 2)
  236. GO
  237. SET IDENTITY_INSERT [post_tags] OFF
  238. GO
  239. SET IDENTITY_INSERT [posts] ON
  240. GO
  241. INSERT [posts] ([id], [user_id], [category_id], [content]) VALUES (1, 1, 1, N'blog started')
  242. GO
  243. INSERT [posts] ([id], [user_id], [category_id], [content]) VALUES (2, 1, 2, N'It works!')
  244. GO
  245. SET IDENTITY_INSERT [posts] OFF
  246. GO
  247. SET IDENTITY_INSERT [tags] ON
  248. GO
  249. INSERT [tags] ([id], [name]) VALUES (1, N'funny')
  250. GO
  251. INSERT [tags] ([id], [name]) VALUES (2, N'important')
  252. GO
  253. SET IDENTITY_INSERT [tags] OFF
  254. GO
  255. SET IDENTITY_INSERT [users] ON
  256. GO
  257. INSERT [users] ([id], [username], [password], [location]) VALUES (1, N'user1', N'pass1', NULL)
  258. GO
  259. INSERT [users] ([id], [username], [password], [location]) VALUES (2, N'user2', N'pass2', NULL)
  260. GO
  261. SET IDENTITY_INSERT [users] OFF
  262. GO
  263. SET IDENTITY_INSERT [countries] ON
  264. GO
  265. INSERT [countries] ([id], [name], [shape]) VALUES (1, N'Left', N'POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))')
  266. GO
  267. INSERT [countries] ([id], [name], [shape]) VALUES (2, N'Right', N'POLYGON ((70 10, 80 40, 60 40, 50 20, 70 10))')
  268. GO
  269. SET IDENTITY_INSERT [countries] OFF
  270. GO
  271. SET IDENTITY_INSERT [events] ON
  272. GO
  273. INSERT [events] ([id], [name], [datetime]) VALUES (1, N'Launch', N'2016-01-01 13:01:01.111')
  274. GO
  275. SET IDENTITY_INSERT [events] OFF
  276. GO
  277. SET IDENTITY_INSERT [products] ON
  278. GO
  279. INSERT [products] ([id], [name], [price]) VALUES (1, N'Calculator', N'23.01')
  280. GO
  281. SET IDENTITY_INSERT [products] OFF
  282. GO
  283. ALTER TABLE [comments] WITH CHECK ADD CONSTRAINT [FK_comments_posts] FOREIGN KEY([post_id])
  284. REFERENCES [posts] ([id])
  285. GO
  286. ALTER TABLE [comments] CHECK CONSTRAINT [FK_comments_posts]
  287. GO
  288. ALTER TABLE [post_tags] WITH CHECK ADD CONSTRAINT [FK_post_tags_posts] FOREIGN KEY([post_id])
  289. REFERENCES [posts] ([id])
  290. GO
  291. ALTER TABLE [post_tags] CHECK CONSTRAINT [FK_post_tags_posts]
  292. GO
  293. ALTER TABLE [post_tags] WITH CHECK ADD CONSTRAINT [FK_post_tags_tags] FOREIGN KEY([tag_id])
  294. REFERENCES [tags] ([id])
  295. GO
  296. ALTER TABLE [post_tags] CHECK CONSTRAINT [FK_post_tags_tags]
  297. GO
  298. ALTER TABLE [posts] WITH CHECK ADD CONSTRAINT [FK_posts_categories] FOREIGN KEY([category_id])
  299. REFERENCES [categories] ([id])
  300. GO
  301. ALTER TABLE [posts] CHECK CONSTRAINT [FK_posts_categories]
  302. GO
  303. ALTER TABLE [posts] WITH CHECK ADD CONSTRAINT [FK_posts_users] FOREIGN KEY([user_id])
  304. REFERENCES [users] ([id])
  305. GO
  306. ALTER TABLE [posts] CHECK CONSTRAINT [FK_posts_users]
  307. GO