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 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. IF (OBJECT_ID('kunsthåndværk_user_id_fkey', 'F') IS NOT NULL)
  2. BEGIN
  3. ALTER TABLE [kunsthåndværk] DROP CONSTRAINT [kunsthåndværk_user_id_fkey]
  4. END
  5. GO
  6. IF (OBJECT_ID('barcodes_product_id_fkey', 'F') IS NOT NULL)
  7. BEGIN
  8. ALTER TABLE [barcodes] DROP CONSTRAINT [barcodes_product_id_fkey]
  9. END
  10. GO
  11. IF (OBJECT_ID('posts_user_id_fkey', 'F') IS NOT NULL)
  12. BEGIN
  13. ALTER TABLE [posts] DROP CONSTRAINT [posts_user_id_fkey]
  14. END
  15. GO
  16. IF (OBJECT_ID('posts_category_id_fkey', 'F') IS NOT NULL)
  17. BEGIN
  18. ALTER TABLE [posts] DROP CONSTRAINT [posts_category_id_fkey]
  19. END
  20. GO
  21. IF (OBJECT_ID('post_tags_tag_id_fkey', 'F') IS NOT NULL)
  22. BEGIN
  23. ALTER TABLE [post_tags] DROP CONSTRAINT [post_tags_tag_id_fkey]
  24. END
  25. GO
  26. IF (OBJECT_ID('post_tags_post_id_fkey', 'F') IS NOT NULL)
  27. BEGIN
  28. ALTER TABLE [post_tags] DROP CONSTRAINT [post_tags_post_id_fkey]
  29. END
  30. GO
  31. IF (OBJECT_ID('comments_post_id_fkey', 'F') IS NOT NULL)
  32. BEGIN
  33. ALTER TABLE [comments] DROP CONSTRAINT [comments_post_id_fkey]
  34. END
  35. GO
  36. IF (OBJECT_ID('comments_category_id_fkey', 'F') IS NOT NULL)
  37. BEGIN
  38. ALTER TABLE [comments] DROP CONSTRAINT [comments_category_id_fkey]
  39. END
  40. GO
  41. IF (OBJECT_ID('barcodes2', 'U') IS NOT NULL)
  42. BEGIN
  43. DROP TABLE [barcodes2]
  44. END
  45. GO
  46. IF (OBJECT_ID('barcodes', 'U') IS NOT NULL)
  47. BEGIN
  48. DROP TABLE [barcodes]
  49. END
  50. GO
  51. IF (OBJECT_ID('products', 'U') IS NOT NULL)
  52. BEGIN
  53. DROP TABLE [products]
  54. END
  55. GO
  56. IF (OBJECT_ID('events', 'U') IS NOT NULL)
  57. BEGIN
  58. DROP TABLE [events]
  59. END
  60. GO
  61. IF (OBJECT_ID('countries', 'U') IS NOT NULL)
  62. BEGIN
  63. DROP TABLE [countries]
  64. END
  65. GO
  66. IF (OBJECT_ID('users', 'U') IS NOT NULL)
  67. BEGIN
  68. DROP TABLE [users]
  69. END
  70. GO
  71. IF (OBJECT_ID('tags', 'U') IS NOT NULL)
  72. BEGIN
  73. DROP TABLE [tags]
  74. END
  75. GO
  76. IF (OBJECT_ID('posts', 'U') IS NOT NULL)
  77. BEGIN
  78. DROP TABLE [posts]
  79. END
  80. GO
  81. IF (OBJECT_ID('post_tags', 'U') IS NOT NULL)
  82. BEGIN
  83. DROP TABLE [post_tags]
  84. END
  85. GO
  86. IF (OBJECT_ID('comments', 'U') IS NOT NULL)
  87. BEGIN
  88. DROP TABLE [comments]
  89. END
  90. GO
  91. IF (OBJECT_ID('categories', 'U') IS NOT NULL)
  92. BEGIN
  93. DROP TABLE [categories]
  94. END
  95. GO
  96. IF (OBJECT_ID('tag_usage', 'V') IS NOT NULL)
  97. BEGIN
  98. DROP VIEW [tag_usage]
  99. END
  100. GO
  101. IF (OBJECT_ID('kunsthåndværk', 'U') IS NOT NULL)
  102. BEGIN
  103. DROP TABLE [kunsthåndværk]
  104. END
  105. GO
  106. IF (OBJECT_ID('invisibles', 'U') IS NOT NULL)
  107. BEGIN
  108. DROP TABLE [invisibles]
  109. END
  110. GO
  111. IF (OBJECT_ID('nopk', 'U') IS NOT NULL)
  112. BEGIN
  113. DROP TABLE [nopk]
  114. END
  115. GO
  116. DROP SEQUENCE IF EXISTS [categories_id_seq]
  117. GO
  118. CREATE SEQUENCE [categories_id_seq] AS int START WITH 1 INCREMENT BY 1 NO CACHE
  119. GO
  120. CREATE TABLE [categories](
  121. [id] [int] NOT NULL CONSTRAINT [categories_id_def] DEFAULT NEXT VALUE FOR [categories_id_seq],
  122. [name] [nvarchar](255) NOT NULL,
  123. [icon] [image],
  124. CONSTRAINT [categories_pkey] PRIMARY KEY CLUSTERED([id] ASC)
  125. )
  126. GO
  127. DROP SEQUENCE IF EXISTS [comments_id_seq]
  128. GO
  129. CREATE SEQUENCE [comments_id_seq] AS bigint START WITH 1 INCREMENT BY 1 NO CACHE
  130. GO
  131. CREATE TABLE [comments](
  132. [id] [bigint] NOT NULL CONSTRAINT [comments_id_def] DEFAULT NEXT VALUE FOR [comments_id_seq],
  133. [post_id] [int] NOT NULL,
  134. [message] [nvarchar](255) NOT NULL,
  135. [category_id] [int] NOT NULL,
  136. CONSTRAINT [comments_pkey] PRIMARY KEY CLUSTERED([id] ASC)
  137. )
  138. GO
  139. DROP SEQUENCE IF EXISTS [post_tags_id_seq]
  140. GO
  141. CREATE SEQUENCE [post_tags_id_seq] AS int START WITH 1 INCREMENT BY 1 NO CACHE
  142. GO
  143. CREATE TABLE [post_tags](
  144. [id] [int] NOT NULL CONSTRAINT [post_tags_id_def] DEFAULT NEXT VALUE FOR [post_tags_id_seq],
  145. [post_id] [int] NOT NULL,
  146. [tag_id] [int] NOT NULL,
  147. CONSTRAINT [post_tags_pkey] PRIMARY KEY CLUSTERED([id] ASC)
  148. )
  149. GO
  150. DROP SEQUENCE IF EXISTS [posts_id_seq]
  151. GO
  152. CREATE SEQUENCE [posts_id_seq] AS int START WITH 1 INCREMENT BY 1 NO CACHE
  153. GO
  154. CREATE TABLE [posts](
  155. [id] [int] NOT NULL CONSTRAINT [posts_id_def] DEFAULT NEXT VALUE FOR [posts_id_seq],
  156. [user_id] [int] NOT NULL,
  157. [category_id] [int] NOT NULL,
  158. [content] [nvarchar](255) NOT NULL,
  159. CONSTRAINT [posts_pkey] PRIMARY KEY CLUSTERED([id] ASC)
  160. )
  161. GO
  162. DROP SEQUENCE IF EXISTS [tags_id_seq]
  163. GO
  164. CREATE SEQUENCE [tags_id_seq] AS int START WITH 1 INCREMENT BY 1 NO CACHE
  165. GO
  166. CREATE TABLE [tags](
  167. [id] [int] NOT NULL CONSTRAINT [tags_id_def] DEFAULT NEXT VALUE FOR [tags_id_seq],
  168. [name] [nvarchar](255) NOT NULL,
  169. [is_important] [bit] NOT NULL,
  170. CONSTRAINT [tags_pkey] PRIMARY KEY CLUSTERED([id] ASC)
  171. )
  172. GO
  173. DROP SEQUENCE IF EXISTS [users_id_seq]
  174. GO
  175. CREATE SEQUENCE [users_id_seq] AS int START WITH 1 INCREMENT BY 1 NO CACHE
  176. GO
  177. CREATE TABLE [users](
  178. [id] [int] NOT NULL CONSTRAINT [users_id_def] DEFAULT NEXT VALUE FOR [users_id_seq],
  179. [username] [nvarchar](255) NOT NULL,
  180. [password] [nvarchar](255) NOT NULL,
  181. [location] [geometry],
  182. CONSTRAINT [users_pkey] PRIMARY KEY CLUSTERED([id] ASC)
  183. )
  184. GO
  185. DROP SEQUENCE IF EXISTS [countries_id_seq]
  186. GO
  187. CREATE SEQUENCE [countries_id_seq] AS int START WITH 1 INCREMENT BY 1 NO CACHE
  188. GO
  189. CREATE TABLE [countries](
  190. [id] [int] NOT NULL CONSTRAINT [countries_id_def] DEFAULT NEXT VALUE FOR [countries_id_seq],
  191. [name] [nvarchar](255) NOT NULL,
  192. [shape] [geometry] NOT NULL,
  193. CONSTRAINT [countries_pkey] PRIMARY KEY CLUSTERED([id] ASC)
  194. )
  195. GO
  196. DROP SEQUENCE IF EXISTS [events_id_seq]
  197. GO
  198. CREATE SEQUENCE [events_id_seq] AS int START WITH 1 INCREMENT BY 1 NO CACHE
  199. GO
  200. CREATE TABLE [events](
  201. [id] [int] NOT NULL CONSTRAINT [events_id_def] DEFAULT NEXT VALUE FOR [events_id_seq],
  202. [name] [nvarchar](255) NOT NULL,
  203. [datetime] [datetime2](0),
  204. [visitors] [bigint],
  205. CONSTRAINT [events_pkey] PRIMARY KEY CLUSTERED([id] ASC)
  206. )
  207. GO
  208. CREATE VIEW [tag_usage]
  209. AS
  210. 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
  211. GO
  212. DROP SEQUENCE IF EXISTS [products_id_seq]
  213. GO
  214. CREATE SEQUENCE [products_id_seq] AS int START WITH 1 INCREMENT BY 1 NO CACHE
  215. GO
  216. CREATE TABLE [products](
  217. [id] [int] NOT NULL CONSTRAINT [products_id_def] DEFAULT NEXT VALUE FOR [products_id_seq],
  218. [name] [nvarchar](255) NOT NULL,
  219. [price] [decimal](10,2) NOT NULL,
  220. [properties] [xml] NOT NULL,
  221. [created_at] [datetime2](0) NOT NULL,
  222. [deleted_at] [datetime2](0),
  223. CONSTRAINT [products_pkey] PRIMARY KEY CLUSTERED([id] ASC)
  224. )
  225. GO
  226. DROP SEQUENCE IF EXISTS [barcodes_id_seq]
  227. GO
  228. CREATE SEQUENCE [barcodes_id_seq] AS int START WITH 1 INCREMENT BY 1 NO CACHE
  229. GO
  230. CREATE TABLE [barcodes](
  231. [id] [int] NOT NULL CONSTRAINT [barcodes_id_def] DEFAULT NEXT VALUE FOR [barcodes_id_seq],
  232. [product_id] [int] NOT NULL,
  233. [hex] [nvarchar](255) NOT NULL,
  234. [bin] [varbinary](max) NOT NULL,
  235. [ip_address] [nvarchar](15),
  236. CONSTRAINT [barcodes_pkey] PRIMARY KEY CLUSTERED([id] ASC)
  237. )
  238. GO
  239. CREATE TABLE [kunsthåndværk](
  240. [id] [nvarchar](36) NOT NULL,
  241. [Umlauts ä_ö_ü-COUNT] [int] NOT NULL,
  242. [user_id] [int] NOT NULL,
  243. [invisible] [nvarchar](36),
  244. CONSTRAINT [kunsthåndværk_pkey] PRIMARY KEY CLUSTERED([id] ASC)
  245. )
  246. GO
  247. CREATE TABLE [invisibles](
  248. [id] [nvarchar](36) NOT NULL,
  249. CONSTRAINT [invisibles_pkey] PRIMARY KEY CLUSTERED([id] ASC)
  250. )
  251. GO
  252. CREATE TABLE [nopk](
  253. [id] [nvarchar](36) NOT NULL
  254. )
  255. GO
  256. INSERT [categories] ([name], [icon]) VALUES (N'announcement', NULL)
  257. GO
  258. INSERT [categories] ([name], [icon]) VALUES (N'article', NULL)
  259. GO
  260. INSERT [categories] ([name], [icon]) VALUES (N'comment', NULL)
  261. GO
  262. INSERT [comments] ([post_id], [message], [category_id]) VALUES (1, N'great', 3)
  263. GO
  264. INSERT [comments] ([post_id], [message], [category_id]) VALUES (1, N'fantastic', 3)
  265. GO
  266. INSERT [comments] ([post_id], [message], [category_id]) VALUES (2, N'thank you', 3)
  267. GO
  268. INSERT [comments] ([post_id], [message], [category_id]) VALUES (2, N'awesome', 3)
  269. GO
  270. INSERT [post_tags] ([post_id], [tag_id]) VALUES (1, 1)
  271. GO
  272. INSERT [post_tags] ([post_id], [tag_id]) VALUES (1, 2)
  273. GO
  274. INSERT [post_tags] ([post_id], [tag_id]) VALUES (2, 1)
  275. GO
  276. INSERT [post_tags] ([post_id], [tag_id]) VALUES (2, 2)
  277. GO
  278. INSERT [posts] ([user_id], [category_id], [content]) VALUES (1, 1, N'blog started')
  279. GO
  280. INSERT [posts] ([user_id], [category_id], [content]) VALUES (1, 2, N'It works!')
  281. GO
  282. INSERT [tags] ([name], [is_important]) VALUES (N'funny', 0)
  283. GO
  284. INSERT [tags] ([name], [is_important]) VALUES (N'important', 1)
  285. GO
  286. INSERT [users] ([username], [password], [location]) VALUES (N'user1', N'pass1', NULL)
  287. GO
  288. INSERT [users] ([username], [password], [location]) VALUES (N'user2', N'pass2', NULL)
  289. GO
  290. INSERT [countries] ([name], [shape]) VALUES (N'Left', N'POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))')
  291. GO
  292. INSERT [countries] ([name], [shape]) VALUES (N'Right', N'POLYGON ((70 10, 80 40, 60 40, 50 20, 70 10))')
  293. GO
  294. INSERT [events] ([name], [datetime], [visitors]) VALUES (N'Launch', N'2016-01-01 13:01:01', 0)
  295. GO
  296. 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')
  297. GO
  298. INSERT [barcodes] ([product_id], [hex], [bin], [ip_address]) VALUES (1, N'00ff01', 0x00ff01, N'127.0.0.1')
  299. GO
  300. INSERT [kunsthåndværk] ([id], [Umlauts ä_ö_ü-COUNT], [user_id], [invisible]) VALUES ('e42c77c6-06a4-4502-816c-d112c7142e6d', 1, 1, NULL)
  301. GO
  302. INSERT [kunsthåndværk] ([id], [Umlauts ä_ö_ü-COUNT], [user_id], [invisible]) VALUES ('e31ecfe6-591f-4660-9fbd-1a232083037f', 2, 2, NULL)
  303. GO
  304. INSERT [invisibles] ([id]) VALUES ('e42c77c6-06a4-4502-816c-d112c7142e6d')
  305. GO
  306. INSERT [nopk] ([id]) VALUES ('e42c77c6-06a4-4502-816c-d112c7142e6d')
  307. GO
  308. ALTER TABLE [comments] WITH CHECK ADD CONSTRAINT [comments_post_id_fkey] FOREIGN KEY([post_id])
  309. REFERENCES [posts] ([id])
  310. GO
  311. ALTER TABLE [comments] CHECK CONSTRAINT [comments_post_id_fkey]
  312. GO
  313. ALTER TABLE [comments] WITH CHECK ADD CONSTRAINT [comments_category_id_fkey] FOREIGN KEY([category_id])
  314. REFERENCES [categories] ([id])
  315. GO
  316. ALTER TABLE [comments] CHECK CONSTRAINT [comments_category_id_fkey]
  317. GO
  318. ALTER TABLE [post_tags] WITH CHECK ADD CONSTRAINT [post_tags_post_id_fkey] FOREIGN KEY([post_id])
  319. REFERENCES [posts] ([id])
  320. GO
  321. ALTER TABLE [post_tags] CHECK CONSTRAINT [post_tags_post_id_fkey]
  322. GO
  323. ALTER TABLE [post_tags] WITH CHECK ADD CONSTRAINT [post_tags_tag_id_fkey] FOREIGN KEY([tag_id])
  324. REFERENCES [tags] ([id])
  325. GO
  326. ALTER TABLE [post_tags] CHECK CONSTRAINT [post_tags_tag_id_fkey]
  327. GO
  328. ALTER TABLE [posts] WITH CHECK ADD CONSTRAINT [posts_category_id_fkey] FOREIGN KEY([category_id])
  329. REFERENCES [categories] ([id])
  330. GO
  331. ALTER TABLE [posts] CHECK CONSTRAINT [posts_category_id_fkey]
  332. GO
  333. ALTER TABLE [posts] WITH CHECK ADD CONSTRAINT [posts_user_id_fkey] FOREIGN KEY([user_id])
  334. REFERENCES [users] ([id])
  335. GO
  336. ALTER TABLE [posts] CHECK CONSTRAINT [posts_user_id_fkey]
  337. GO
  338. ALTER TABLE [barcodes] WITH CHECK ADD CONSTRAINT [barcodes_product_id_fkey] FOREIGN KEY([product_id])
  339. REFERENCES [products] ([id])
  340. GO
  341. ALTER TABLE [barcodes] CHECK CONSTRAINT [barcodes_product_id_fkey]
  342. GO
  343. ALTER TABLE [kunsthåndværk] WITH CHECK ADD CONSTRAINT [UC_kunsthåndværk_Umlauts ä_ö_ü-COUNT] UNIQUE([Umlauts ä_ö_ü-COUNT])
  344. GO
  345. ALTER TABLE [kunsthåndværk] WITH CHECK ADD CONSTRAINT [kunsthåndværk_user_id_fkey] FOREIGN KEY([user_id])
  346. REFERENCES [users] ([id])
  347. GO
  348. ALTER TABLE [kunsthåndværk] CHECK CONSTRAINT [kunsthåndværk_user_id_fkey]
  349. GO