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
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

blog_sqlsrv.sql 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  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. [invisible_id] [nvarchar](36),
  245. CONSTRAINT [kunsthåndværk_pkey] PRIMARY KEY CLUSTERED([id] ASC)
  246. )
  247. GO
  248. CREATE TABLE [invisibles](
  249. [id] [nvarchar](36) NOT NULL,
  250. CONSTRAINT [invisibles_pkey] PRIMARY KEY CLUSTERED([id] ASC)
  251. )
  252. GO
  253. CREATE TABLE [nopk](
  254. [id] [nvarchar](36) NOT NULL
  255. )
  256. GO
  257. INSERT [categories] ([name], [icon]) VALUES (N'announcement', NULL)
  258. GO
  259. INSERT [categories] ([name], [icon]) VALUES (N'article', NULL)
  260. GO
  261. INSERT [categories] ([name], [icon]) VALUES (N'comment', NULL)
  262. GO
  263. INSERT [comments] ([post_id], [message], [category_id]) VALUES (1, N'great', 3)
  264. GO
  265. INSERT [comments] ([post_id], [message], [category_id]) VALUES (1, N'fantastic', 3)
  266. GO
  267. INSERT [comments] ([post_id], [message], [category_id]) VALUES (2, N'thank you', 3)
  268. GO
  269. INSERT [comments] ([post_id], [message], [category_id]) VALUES (2, N'awesome', 3)
  270. GO
  271. INSERT [post_tags] ([post_id], [tag_id]) VALUES (1, 1)
  272. GO
  273. INSERT [post_tags] ([post_id], [tag_id]) VALUES (1, 2)
  274. GO
  275. INSERT [post_tags] ([post_id], [tag_id]) VALUES (2, 1)
  276. GO
  277. INSERT [post_tags] ([post_id], [tag_id]) VALUES (2, 2)
  278. GO
  279. INSERT [posts] ([user_id], [category_id], [content]) VALUES (1, 1, N'blog started')
  280. GO
  281. INSERT [posts] ([user_id], [category_id], [content]) VALUES (1, 2, N'It works!')
  282. GO
  283. INSERT [tags] ([name], [is_important]) VALUES (N'funny', 0)
  284. GO
  285. INSERT [tags] ([name], [is_important]) VALUES (N'important', 1)
  286. GO
  287. INSERT [users] ([username], [password], [location]) VALUES (N'user1', N'pass1', NULL)
  288. GO
  289. INSERT [users] ([username], [password], [location]) VALUES (N'user2', N'$2y$10$cg7/nswxVZ0cmVIsMB/pVOh1OfcHScBJGq7Xu4KF9dFEQgRZ8HWe.', NULL)
  290. GO
  291. INSERT [countries] ([name], [shape]) VALUES (N'Left', N'POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))')
  292. GO
  293. INSERT [countries] ([name], [shape]) VALUES (N'Right', N'POLYGON ((70 10, 80 40, 60 40, 50 20, 70 10))')
  294. GO
  295. INSERT [countries] ([name], [shape]) VALUES (N'Point', N'POINT (30 10)')
  296. GO
  297. INSERT [countries] ([name], [shape]) VALUES (N'Line', N'LINESTRING (30 10, 10 30, 40 40)')
  298. GO
  299. INSERT [countries] ([name], [shape]) VALUES (N'Poly1', N'POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))')
  300. GO
  301. INSERT [countries] ([name], [shape]) VALUES (N'Poly2', N'POLYGON ((35 10, 45 45, 15 40, 10 20, 35 10),(20 30, 35 35, 30 20, 20 30))')
  302. GO
  303. INSERT [countries] ([name], [shape]) VALUES (N'Mpoint', N'MULTIPOINT (10 40, 40 30, 20 20, 30 10)')
  304. GO
  305. INSERT [countries] ([name], [shape]) VALUES (N'Mline', N'MULTILINESTRING ((10 10, 20 20, 10 40),(40 40, 30 30, 40 20, 30 10))')
  306. GO
  307. INSERT [countries] ([name], [shape]) VALUES (N'Mpoly1', N'MULTIPOLYGON (((30 20, 45 40, 10 40, 30 20)),((15 5, 40 10, 10 20, 5 10, 15 5)))')
  308. GO
  309. INSERT [countries] ([name], [shape]) VALUES (N'Mpoly2', N'MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)),((20 35, 10 30, 10 10, 30 5, 45 20, 20 35),(30 20, 20 15, 20 25, 30 20)))')
  310. GO
  311. INSERT [countries] ([name], [shape]) VALUES (N'Gcoll', N'GEOMETRYCOLLECTION(POINT(4 6),LINESTRING(4 6,7 10))')
  312. GO
  313. INSERT [events] ([name], [datetime], [visitors]) VALUES (N'Launch', N'2016-01-01 13:01:01', 0)
  314. GO
  315. 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')
  316. GO
  317. INSERT [barcodes] ([product_id], [hex], [bin], [ip_address]) VALUES (1, N'00ff01', 0x00ff01, N'127.0.0.1')
  318. GO
  319. INSERT [kunsthåndværk] ([id], [Umlauts ä_ö_ü-COUNT], [user_id], [invisible], [invisible_id]) VALUES ('e42c77c6-06a4-4502-816c-d112c7142e6d', 1, 1, NULL, 'e42c77c6-06a4-4502-816c-d112c7142e6d')
  320. GO
  321. INSERT [kunsthåndværk] ([id], [Umlauts ä_ö_ü-COUNT], [user_id], [invisible], [invisible_id]) VALUES ('e31ecfe6-591f-4660-9fbd-1a232083037f', 2, 2, NULL, 'e42c77c6-06a4-4502-816c-d112c7142e6d')
  322. GO
  323. INSERT [invisibles] ([id]) VALUES ('e42c77c6-06a4-4502-816c-d112c7142e6d')
  324. GO
  325. INSERT [nopk] ([id]) VALUES ('e42c77c6-06a4-4502-816c-d112c7142e6d')
  326. GO
  327. ALTER TABLE [comments] WITH CHECK ADD CONSTRAINT [comments_post_id_fkey] FOREIGN KEY([post_id])
  328. REFERENCES [posts] ([id])
  329. GO
  330. ALTER TABLE [comments] CHECK CONSTRAINT [comments_post_id_fkey]
  331. GO
  332. ALTER TABLE [comments] WITH CHECK ADD CONSTRAINT [comments_category_id_fkey] FOREIGN KEY([category_id])
  333. REFERENCES [categories] ([id])
  334. GO
  335. ALTER TABLE [comments] CHECK CONSTRAINT [comments_category_id_fkey]
  336. GO
  337. ALTER TABLE [post_tags] WITH CHECK ADD CONSTRAINT [post_tags_post_id_fkey] FOREIGN KEY([post_id])
  338. REFERENCES [posts] ([id])
  339. GO
  340. ALTER TABLE [post_tags] CHECK CONSTRAINT [post_tags_post_id_fkey]
  341. GO
  342. ALTER TABLE [post_tags] WITH CHECK ADD CONSTRAINT [post_tags_tag_id_fkey] FOREIGN KEY([tag_id])
  343. REFERENCES [tags] ([id])
  344. GO
  345. ALTER TABLE [post_tags] CHECK CONSTRAINT [post_tags_tag_id_fkey]
  346. GO
  347. ALTER TABLE [posts] WITH CHECK ADD CONSTRAINT [posts_category_id_fkey] FOREIGN KEY([category_id])
  348. REFERENCES [categories] ([id])
  349. GO
  350. ALTER TABLE [posts] CHECK CONSTRAINT [posts_category_id_fkey]
  351. GO
  352. ALTER TABLE [posts] WITH CHECK ADD CONSTRAINT [posts_user_id_fkey] FOREIGN KEY([user_id])
  353. REFERENCES [users] ([id])
  354. GO
  355. ALTER TABLE [posts] CHECK CONSTRAINT [posts_user_id_fkey]
  356. GO
  357. ALTER TABLE [barcodes] WITH CHECK ADD CONSTRAINT [barcodes_product_id_fkey] FOREIGN KEY([product_id])
  358. REFERENCES [products] ([id])
  359. GO
  360. ALTER TABLE [barcodes] CHECK CONSTRAINT [barcodes_product_id_fkey]
  361. GO
  362. ALTER TABLE [kunsthåndværk] WITH CHECK ADD CONSTRAINT [UC_kunsthåndværk_Umlauts ä_ö_ü-COUNT] UNIQUE([Umlauts ä_ö_ü-COUNT])
  363. GO
  364. ALTER TABLE [kunsthåndværk] WITH CHECK ADD CONSTRAINT [kunsthåndværk_user_id_fkey] FOREIGN KEY([user_id])
  365. REFERENCES [users] ([id])
  366. GO
  367. ALTER TABLE [kunsthåndværk] CHECK CONSTRAINT [kunsthåndværk_user_id_fkey]
  368. GO
  369. ALTER TABLE [kunsthåndværk] WITH CHECK ADD CONSTRAINT [kunsthåndværk_invisible_id_fkey] FOREIGN KEY([invisible_id])
  370. REFERENCES [invisibles] ([id])
  371. GO
  372. ALTER TABLE [kunsthåndværk] CHECK CONSTRAINT [kunsthåndværk_invisible_id_fkey]
  373. GO