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_sqlsrv.sql 8.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. IF (OBJECT_ID('FK_kunsthåndværk_users', 'F') IS NOT NULL)
  2. BEGIN
  3. ALTER TABLE [kunsthåndværk] DROP CONSTRAINT [FK_kunsthåndværk_users]
  4. END
  5. GO
  6. IF (OBJECT_ID('FK_barcodes_products', 'F') IS NOT NULL)
  7. BEGIN
  8. ALTER TABLE [barcodes] DROP CONSTRAINT [FK_barcodes_products]
  9. END
  10. GO
  11. IF (OBJECT_ID('FK_posts_users', 'F') IS NOT NULL)
  12. BEGIN
  13. ALTER TABLE [posts] DROP CONSTRAINT [FK_posts_users]
  14. END
  15. GO
  16. IF (OBJECT_ID('FK_posts_categories', 'F') IS NOT NULL)
  17. BEGIN
  18. ALTER TABLE [posts] DROP CONSTRAINT [FK_posts_categories]
  19. END
  20. GO
  21. IF (OBJECT_ID('FK_post_tags_tags', 'F') IS NOT NULL)
  22. BEGIN
  23. ALTER TABLE [post_tags] DROP CONSTRAINT [FK_post_tags_tags]
  24. END
  25. GO
  26. IF (OBJECT_ID('FK_post_tags_posts', 'F') IS NOT NULL)
  27. BEGIN
  28. ALTER TABLE [post_tags] DROP CONSTRAINT [FK_post_tags_posts]
  29. END
  30. GO
  31. IF (OBJECT_ID('FK_comments_posts', 'F') IS NOT NULL)
  32. BEGIN
  33. ALTER TABLE [comments] DROP CONSTRAINT [FK_comments_posts]
  34. END
  35. GO
  36. IF (OBJECT_ID('barcodes2', 'U') IS NOT NULL)
  37. BEGIN
  38. DROP TABLE [barcodes2]
  39. END
  40. GO
  41. IF (OBJECT_ID('barcodes', 'U') IS NOT NULL)
  42. BEGIN
  43. DROP TABLE [barcodes]
  44. END
  45. GO
  46. IF (OBJECT_ID('products', 'U') IS NOT NULL)
  47. BEGIN
  48. DROP TABLE [products]
  49. END
  50. GO
  51. IF (OBJECT_ID('events', 'U') IS NOT NULL)
  52. BEGIN
  53. DROP TABLE [events]
  54. END
  55. GO
  56. IF (OBJECT_ID('countries', 'U') IS NOT NULL)
  57. BEGIN
  58. DROP TABLE [countries]
  59. END
  60. GO
  61. IF (OBJECT_ID('users', 'U') IS NOT NULL)
  62. BEGIN
  63. DROP TABLE [users]
  64. END
  65. GO
  66. IF (OBJECT_ID('tags', 'U') IS NOT NULL)
  67. BEGIN
  68. DROP TABLE [tags]
  69. END
  70. GO
  71. IF (OBJECT_ID('posts', 'U') IS NOT NULL)
  72. BEGIN
  73. DROP TABLE [posts]
  74. END
  75. GO
  76. IF (OBJECT_ID('post_tags', 'U') IS NOT NULL)
  77. BEGIN
  78. DROP TABLE [post_tags]
  79. END
  80. GO
  81. IF (OBJECT_ID('comments', 'U') IS NOT NULL)
  82. BEGIN
  83. DROP TABLE [comments]
  84. END
  85. GO
  86. IF (OBJECT_ID('categories', 'U') IS NOT NULL)
  87. BEGIN
  88. DROP TABLE [categories]
  89. END
  90. GO
  91. IF (OBJECT_ID('tag_usage', 'V') IS NOT NULL)
  92. BEGIN
  93. DROP VIEW [tag_usage]
  94. END
  95. GO
  96. IF (OBJECT_ID('kunsthåndværk', 'U') IS NOT NULL)
  97. BEGIN
  98. DROP TABLE [kunsthåndværk]
  99. END
  100. GO
  101. IF (OBJECT_ID('invisibles', 'U') IS NOT NULL)
  102. BEGIN
  103. DROP TABLE [invisibles]
  104. END
  105. GO
  106. IF (OBJECT_ID('nopk', 'U') IS NOT NULL)
  107. BEGIN
  108. DROP TABLE [nopk]
  109. END
  110. GO
  111. CREATE TABLE [categories](
  112. [id] [int] IDENTITY,
  113. [name] [nvarchar](255) NOT NULL,
  114. [icon] [image],
  115. PRIMARY KEY CLUSTERED([id] ASC)
  116. )
  117. GO
  118. CREATE TABLE [comments](
  119. [id] [bigint] IDENTITY,
  120. [post_id] [int] NOT NULL,
  121. [message] [nvarchar](255) NOT NULL,
  122. PRIMARY KEY CLUSTERED([id] ASC)
  123. )
  124. GO
  125. CREATE TABLE [post_tags](
  126. [id] [int] IDENTITY,
  127. [post_id] [int] NOT NULL,
  128. [tag_id] [int] NOT NULL,
  129. PRIMARY KEY CLUSTERED([id] ASC)
  130. )
  131. GO
  132. CREATE TABLE [posts](
  133. [id] [int] IDENTITY,
  134. [user_id] [int] NOT NULL,
  135. [category_id] [int] NOT NULL,
  136. [content] [nvarchar](255) NOT NULL,
  137. PRIMARY KEY CLUSTERED([id] ASC)
  138. )
  139. GO
  140. CREATE TABLE [tags](
  141. [id] [int] IDENTITY,
  142. [name] [nvarchar](255) NOT NULL,
  143. [is_important] [bit] NOT NULL,
  144. PRIMARY KEY CLUSTERED([id] ASC)
  145. )
  146. GO
  147. CREATE TABLE [users](
  148. [id] [int] IDENTITY,
  149. [username] [nvarchar](255) NOT NULL,
  150. [password] [nvarchar](255) NOT NULL,
  151. [location] [geometry],
  152. CONSTRAINT [PK_users]
  153. PRIMARY KEY CLUSTERED([id] ASC)
  154. )
  155. GO
  156. CREATE TABLE [countries](
  157. [id] [int] IDENTITY,
  158. [name] [nvarchar](255) NOT NULL,
  159. [shape] [geometry] NOT NULL,
  160. CONSTRAINT [PK_countries]
  161. PRIMARY KEY CLUSTERED([id] ASC)
  162. )
  163. GO
  164. CREATE TABLE [events](
  165. [id] [int] IDENTITY,
  166. [name] [nvarchar](255) NOT NULL,
  167. [datetime] [datetime2](0),
  168. [visitors] [bigint],
  169. CONSTRAINT [PK_events]
  170. PRIMARY KEY CLUSTERED([id] ASC)
  171. )
  172. GO
  173. CREATE VIEW [tag_usage]
  174. AS
  175. SELECT top 100 PERCENT name, COUNT_BIG(name) AS [count] FROM tags, post_tags WHERE tags.id = post_tags.tag_id GROUP BY name ORDER BY [count] DESC, name
  176. GO
  177. CREATE TABLE [products](
  178. [id] [int] IDENTITY,
  179. [name] [nvarchar](255) NOT NULL,
  180. [price] [decimal](10,2) NOT NULL,
  181. [properties] [xml] NOT NULL,
  182. [created_at] [datetime2](0) NOT NULL,
  183. [deleted_at] [datetime2](0),
  184. CONSTRAINT [PK_products]
  185. PRIMARY KEY CLUSTERED([id] ASC)
  186. )
  187. GO
  188. CREATE TABLE [barcodes](
  189. [id] [int] IDENTITY,
  190. [product_id] [int] NOT NULL,
  191. [hex] [nvarchar](255) NOT NULL,
  192. [bin] [varbinary](max) NOT NULL,
  193. CONSTRAINT [PK_barcodes]
  194. PRIMARY KEY CLUSTERED([id] ASC)
  195. )
  196. GO
  197. CREATE TABLE [kunsthåndværk](
  198. [id] [nvarchar](36) NOT NULL,
  199. [Umlauts ä_ö_ü-COUNT] [int] NOT NULL,
  200. [user_id] [int] NOT NULL,
  201. [invisible] [nvarchar](36),
  202. CONSTRAINT [PK_kunsthåndværk]
  203. PRIMARY KEY CLUSTERED([id] ASC)
  204. )
  205. GO
  206. CREATE TABLE [invisibles](
  207. [id] [nvarchar](36) NOT NULL,
  208. CONSTRAINT [PK_invisibles]
  209. PRIMARY KEY CLUSTERED([id] ASC)
  210. )
  211. GO
  212. CREATE TABLE [nopk](
  213. [id] [nvarchar](36) NOT NULL
  214. )
  215. GO
  216. INSERT [categories] ([name], [icon]) VALUES (N'announcement', NULL)
  217. GO
  218. INSERT [categories] ([name], [icon]) VALUES (N'article', NULL)
  219. GO
  220. INSERT [comments] ([post_id], [message]) VALUES (1, N'great')
  221. GO
  222. INSERT [comments] ([post_id], [message]) VALUES (1, N'fantastic')
  223. GO
  224. INSERT [comments] ([post_id], [message]) VALUES (2, N'thank you')
  225. GO
  226. INSERT [comments] ([post_id], [message]) VALUES (2, N'awesome')
  227. GO
  228. INSERT [post_tags] ([post_id], [tag_id]) VALUES (1, 1)
  229. GO
  230. INSERT [post_tags] ([post_id], [tag_id]) VALUES (1, 2)
  231. GO
  232. INSERT [post_tags] ([post_id], [tag_id]) VALUES (2, 1)
  233. GO
  234. INSERT [post_tags] ([post_id], [tag_id]) VALUES (2, 2)
  235. GO
  236. INSERT [posts] ([user_id], [category_id], [content]) VALUES (1, 1, N'blog started')
  237. GO
  238. INSERT [posts] ([user_id], [category_id], [content]) VALUES (1, 2, N'It works!')
  239. GO
  240. INSERT [tags] ([name], [is_important]) VALUES (N'funny', 0)
  241. GO
  242. INSERT [tags] ([name], [is_important]) VALUES (N'important', 1)
  243. GO
  244. INSERT [users] ([username], [password], [location]) VALUES (N'user1', N'pass1', NULL)
  245. GO
  246. INSERT [users] ([username], [password], [location]) VALUES (N'user2', N'pass2', NULL)
  247. GO
  248. INSERT [countries] ([name], [shape]) VALUES (N'Left', N'POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))')
  249. GO
  250. INSERT [countries] ([name], [shape]) VALUES (N'Right', N'POLYGON ((70 10, 80 40, 60 40, 50 20, 70 10))')
  251. GO
  252. INSERT [events] ([name], [datetime], [visitors]) VALUES (N'Launch', N'2016-01-01 13:01:01', 0)
  253. GO
  254. INSERT [products] ([name], [price], [properties], [created_at]) VALUES (N'Calculator', N'23.01', N'<root type="object"><depth type="boolean">false</depth><model type="string">TRX-120</model><width type="number">100</width><height type="null" /></root>', '1970-01-01 01:01:01')
  255. GO
  256. INSERT [barcodes] ([product_id], [hex], [bin]) VALUES (1, N'00ff01', 0x00ff01)
  257. GO
  258. INSERT [kunsthåndværk] ([id], [Umlauts ä_ö_ü-COUNT], [user_id], [invisible]) VALUES ('e42c77c6-06a4-4502-816c-d112c7142e6d', 1, 1, NULL)
  259. GO
  260. INSERT [kunsthåndværk] ([id], [Umlauts ä_ö_ü-COUNT], [user_id], [invisible]) VALUES ('e31ecfe6-591f-4660-9fbd-1a232083037f', 2, 2, NULL)
  261. GO
  262. INSERT [invisibles] ([id]) VALUES ('e42c77c6-06a4-4502-816c-d112c7142e6d')
  263. GO
  264. INSERT [nopk] ([id]) VALUES ('e42c77c6-06a4-4502-816c-d112c7142e6d')
  265. GO
  266. ALTER TABLE [comments] WITH CHECK ADD CONSTRAINT [FK_comments_posts] FOREIGN KEY([post_id])
  267. REFERENCES [posts] ([id])
  268. GO
  269. ALTER TABLE [comments] CHECK CONSTRAINT [FK_comments_posts]
  270. GO
  271. ALTER TABLE [post_tags] WITH CHECK ADD CONSTRAINT [FK_post_tags_posts] FOREIGN KEY([post_id])
  272. REFERENCES [posts] ([id])
  273. GO
  274. ALTER TABLE [post_tags] CHECK CONSTRAINT [FK_post_tags_posts]
  275. GO
  276. ALTER TABLE [post_tags] WITH CHECK ADD CONSTRAINT [FK_post_tags_tags] FOREIGN KEY([tag_id])
  277. REFERENCES [tags] ([id])
  278. GO
  279. ALTER TABLE [post_tags] CHECK CONSTRAINT [FK_post_tags_tags]
  280. GO
  281. ALTER TABLE [posts] WITH CHECK ADD CONSTRAINT [FK_posts_categories] FOREIGN KEY([category_id])
  282. REFERENCES [categories] ([id])
  283. GO
  284. ALTER TABLE [posts] CHECK CONSTRAINT [FK_posts_categories]
  285. GO
  286. ALTER TABLE [posts] WITH CHECK ADD CONSTRAINT [FK_posts_users] FOREIGN KEY([user_id])
  287. REFERENCES [users] ([id])
  288. GO
  289. ALTER TABLE [posts] CHECK CONSTRAINT [FK_posts_users]
  290. GO
  291. ALTER TABLE [barcodes] WITH CHECK ADD CONSTRAINT [FK_barcodes_products] FOREIGN KEY([product_id])
  292. REFERENCES [products] ([id])
  293. GO
  294. ALTER TABLE [barcodes] CHECK CONSTRAINT [FK_barcodes_products]
  295. GO
  296. ALTER TABLE [kunsthåndværk] WITH CHECK ADD CONSTRAINT [UC_kunsthåndværk_Umlauts ä_ö_ü-COUNT] UNIQUE([Umlauts ä_ö_ü-COUNT])
  297. GO
  298. ALTER TABLE [kunsthåndværk] WITH CHECK ADD CONSTRAINT [FK_kunsthåndværk_users] FOREIGN KEY([user_id])
  299. REFERENCES [users] ([id])
  300. GO
  301. ALTER TABLE [kunsthåndværk] CHECK CONSTRAINT [FK_kunsthåndværk_users]
  302. GO