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
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

blog_sqlserver.sql 8.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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. [visitors] [int] NOT NULL,
  180. CONSTRAINT [PK_events] PRIMARY KEY CLUSTERED
  181. (
  182. [id] ASC
  183. )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  184. ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
  185. GO
  186. SET ANSI_NULLS ON
  187. GO
  188. SET QUOTED_IDENTIFIER ON
  189. GO
  190. CREATE VIEW [tag_usage]
  191. AS
  192. 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
  193. GO
  194. SET ANSI_NULLS ON
  195. GO
  196. SET QUOTED_IDENTIFIER ON
  197. GO
  198. CREATE TABLE [products](
  199. [id] [int] IDENTITY,
  200. [name] [nvarchar](max) NOT NULL,
  201. [price] [decimal](10,2) NOT NULL,
  202. CONSTRAINT [PK_products] PRIMARY KEY CLUSTERED
  203. (
  204. [id] ASC
  205. )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  206. ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
  207. GO
  208. SET IDENTITY_INSERT [categories] ON
  209. GO
  210. INSERT [categories] ([id], [name], [icon]) VALUES (1, N'announcement', NULL)
  211. GO
  212. INSERT [categories] ([id], [name], [icon]) VALUES (2, N'article', NULL)
  213. GO
  214. SET IDENTITY_INSERT [categories] OFF
  215. GO
  216. SET IDENTITY_INSERT [comments] ON
  217. GO
  218. INSERT [comments] ([id], [post_id], [message]) VALUES (1, 1, N'great')
  219. GO
  220. INSERT [comments] ([id], [post_id], [message]) VALUES (2, 1, N'fantastic')
  221. GO
  222. INSERT [comments] ([id], [post_id], [message]) VALUES (3, 2, N'thank you')
  223. GO
  224. INSERT [comments] ([id], [post_id], [message]) VALUES (4, 2, N'awesome')
  225. GO
  226. SET IDENTITY_INSERT [comments] OFF
  227. GO
  228. SET IDENTITY_INSERT [post_tags] ON
  229. GO
  230. INSERT [post_tags] ([id], [post_id], [tag_id]) VALUES (1, 1, 1)
  231. GO
  232. INSERT [post_tags] ([id], [post_id], [tag_id]) VALUES (2, 1, 2)
  233. GO
  234. INSERT [post_tags] ([id], [post_id], [tag_id]) VALUES (3, 2, 1)
  235. GO
  236. INSERT [post_tags] ([id], [post_id], [tag_id]) VALUES (4, 2, 2)
  237. GO
  238. SET IDENTITY_INSERT [post_tags] OFF
  239. GO
  240. SET IDENTITY_INSERT [posts] ON
  241. GO
  242. INSERT [posts] ([id], [user_id], [category_id], [content]) VALUES (1, 1, 1, N'blog started')
  243. GO
  244. INSERT [posts] ([id], [user_id], [category_id], [content]) VALUES (2, 1, 2, N'It works!')
  245. GO
  246. SET IDENTITY_INSERT [posts] OFF
  247. GO
  248. SET IDENTITY_INSERT [tags] ON
  249. GO
  250. INSERT [tags] ([id], [name]) VALUES (1, N'funny')
  251. GO
  252. INSERT [tags] ([id], [name]) VALUES (2, N'important')
  253. GO
  254. SET IDENTITY_INSERT [tags] OFF
  255. GO
  256. SET IDENTITY_INSERT [users] ON
  257. GO
  258. INSERT [users] ([id], [username], [password], [location]) VALUES (1, N'user1', N'pass1', NULL)
  259. GO
  260. INSERT [users] ([id], [username], [password], [location]) VALUES (2, N'user2', N'pass2', NULL)
  261. GO
  262. SET IDENTITY_INSERT [users] OFF
  263. GO
  264. SET IDENTITY_INSERT [countries] ON
  265. GO
  266. INSERT [countries] ([id], [name], [shape]) VALUES (1, N'Left', N'POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))')
  267. GO
  268. INSERT [countries] ([id], [name], [shape]) VALUES (2, N'Right', N'POLYGON ((70 10, 80 40, 60 40, 50 20, 70 10))')
  269. GO
  270. SET IDENTITY_INSERT [countries] OFF
  271. GO
  272. SET IDENTITY_INSERT [events] ON
  273. GO
  274. INSERT [events] ([id], [name], [datetime], [visitors]) VALUES (1, N'Launch', N'2016-01-01 13:01:01.111', 0)
  275. GO
  276. SET IDENTITY_INSERT [events] OFF
  277. GO
  278. SET IDENTITY_INSERT [products] ON
  279. GO
  280. INSERT [products] ([id], [name], [price]) VALUES (1, N'Calculator', N'23.01')
  281. GO
  282. SET IDENTITY_INSERT [products] OFF
  283. GO
  284. ALTER TABLE [comments] WITH CHECK ADD CONSTRAINT [FK_comments_posts] FOREIGN KEY([post_id])
  285. REFERENCES [posts] ([id])
  286. GO
  287. ALTER TABLE [comments] CHECK CONSTRAINT [FK_comments_posts]
  288. GO
  289. ALTER TABLE [post_tags] WITH CHECK ADD CONSTRAINT [FK_post_tags_posts] FOREIGN KEY([post_id])
  290. REFERENCES [posts] ([id])
  291. GO
  292. ALTER TABLE [post_tags] CHECK CONSTRAINT [FK_post_tags_posts]
  293. GO
  294. ALTER TABLE [post_tags] WITH CHECK ADD CONSTRAINT [FK_post_tags_tags] FOREIGN KEY([tag_id])
  295. REFERENCES [tags] ([id])
  296. GO
  297. ALTER TABLE [post_tags] CHECK CONSTRAINT [FK_post_tags_tags]
  298. GO
  299. ALTER TABLE [posts] WITH CHECK ADD CONSTRAINT [FK_posts_categories] FOREIGN KEY([category_id])
  300. REFERENCES [categories] ([id])
  301. GO
  302. ALTER TABLE [posts] CHECK CONSTRAINT [FK_posts_categories]
  303. GO
  304. ALTER TABLE [posts] WITH CHECK ADD CONSTRAINT [FK_posts_users] FOREIGN KEY([user_id])
  305. REFERENCES [users] ([id])
  306. GO
  307. ALTER TABLE [posts] CHECK CONSTRAINT [FK_posts_users]
  308. GO