lyfzems.sql 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. USE [master]
  2. GO
  3. /****** Object: Database [lyfzems] Script Date: 2017-05-29 15:54:12 ******/
  4. CREATE DATABASE [lyfzems] ON PRIMARY
  5. ( NAME = N'lyfzems', FILENAME = N'E:\lyfzClassicSoft\服务端\数据\lyfzems.mdf' , SIZE = 3072KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
  6. LOG ON
  7. ( NAME = N'lyfzems_log', FILENAME = N'E:\lyfzClassicSoft\服务端\数据\lyfzems_log.ldf' , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
  8. GO
  9. ALTER DATABASE [lyfzems] SET COMPATIBILITY_LEVEL = 90
  10. GO
  11. IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
  12. begin
  13. EXEC [lyfzems].[dbo].[sp_fulltext_database] @action = 'enable'
  14. end
  15. GO
  16. ALTER DATABASE [lyfzems] SET ANSI_NULL_DEFAULT OFF
  17. GO
  18. ALTER DATABASE [lyfzems] SET ANSI_NULLS OFF
  19. GO
  20. ALTER DATABASE [lyfzems] SET ANSI_PADDING OFF
  21. GO
  22. ALTER DATABASE [lyfzems] SET ANSI_WARNINGS OFF
  23. GO
  24. ALTER DATABASE [lyfzems] SET ARITHABORT OFF
  25. GO
  26. ALTER DATABASE [lyfzems] SET AUTO_CLOSE ON
  27. GO
  28. ALTER DATABASE [lyfzems] SET AUTO_SHRINK OFF
  29. GO
  30. ALTER DATABASE [lyfzems] SET AUTO_UPDATE_STATISTICS ON
  31. GO
  32. ALTER DATABASE [lyfzems] SET CURSOR_CLOSE_ON_COMMIT OFF
  33. GO
  34. ALTER DATABASE [lyfzems] SET CURSOR_DEFAULT GLOBAL
  35. GO
  36. ALTER DATABASE [lyfzems] SET CONCAT_NULL_YIELDS_NULL OFF
  37. GO
  38. ALTER DATABASE [lyfzems] SET NUMERIC_ROUNDABORT OFF
  39. GO
  40. ALTER DATABASE [lyfzems] SET QUOTED_IDENTIFIER OFF
  41. GO
  42. ALTER DATABASE [lyfzems] SET RECURSIVE_TRIGGERS OFF
  43. GO
  44. ALTER DATABASE [lyfzems] SET DISABLE_BROKER
  45. GO
  46. ALTER DATABASE [lyfzems] SET AUTO_UPDATE_STATISTICS_ASYNC OFF
  47. GO
  48. ALTER DATABASE [lyfzems] SET DATE_CORRELATION_OPTIMIZATION OFF
  49. GO
  50. ALTER DATABASE [lyfzems] SET TRUSTWORTHY OFF
  51. GO
  52. ALTER DATABASE [lyfzems] SET ALLOW_SNAPSHOT_ISOLATION OFF
  53. GO
  54. ALTER DATABASE [lyfzems] SET PARAMETERIZATION SIMPLE
  55. GO
  56. ALTER DATABASE [lyfzems] SET READ_COMMITTED_SNAPSHOT OFF
  57. GO
  58. ALTER DATABASE [lyfzems] SET RECOVERY SIMPLE
  59. GO
  60. ALTER DATABASE [lyfzems] SET MULTI_USER
  61. GO
  62. ALTER DATABASE [lyfzems] SET PAGE_VERIFY CHECKSUM
  63. GO
  64. ALTER DATABASE [lyfzems] SET DB_CHAINING OFF
  65. GO
  66. USE [lyfzems]
  67. GO
  68. /****** Object: Table [dbo].[branch] Script Date: 2017-05-29 15:54:12 ******/
  69. SET ANSI_NULLS ON
  70. GO
  71. SET QUOTED_IDENTIFIER ON
  72. GO
  73. CREATE TABLE [dbo].[branch](
  74. [enterprise_id] [nvarchar](10) NOT NULL,
  75. [head_office] [bit] NOT NULL,
  76. [branch_id] [nvarchar](15) NOT NULL,
  77. [branch_name] [nvarchar](64) NOT NULL,
  78. [branch_phone] [nvarchar](32) NULL,
  79. [branch_superintendent] [nvarchar](32) NULL,
  80. [branch_address] [nvarchar](128) NULL,
  81. [branch_account] [nvarchar](16) NULL,
  82. [branch_password] [nvarchar](16) NULL,
  83. [residual_flow] [bigint] NULL,
  84. [branch_note] [nvarchar](255) NULL,
  85. [charges_type] [smallint] NOT NULL,
  86. [date_of_expiry] [nvarchar](32) NULL,
  87. CONSTRAINT [PK_branch] PRIMARY KEY CLUSTERED
  88. (
  89. [branch_id] ASC
  90. )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  91. ) ON [PRIMARY]
  92. GO
  93. /****** Object: Table [dbo].[downloaded_image] Script Date: 2017-05-29 15:54:12 ******/
  94. SET ANSI_NULLS ON
  95. GO
  96. SET QUOTED_IDENTIFIER ON
  97. GO
  98. CREATE TABLE [dbo].[downloaded_image](
  99. [upload_id] [nvarchar](50) NOT NULL,
  100. [download_branch_id] [nvarchar](15) NOT NULL,
  101. [download_image_name] [nvarchar](255) NOT NULL,
  102. [download_image_size] [int] NOT NULL,
  103. [download_datetime] [nvarchar](32) NOT NULL,
  104. CONSTRAINT [PK_tbl_download_record] PRIMARY KEY CLUSTERED
  105. (
  106. [upload_id] ASC,
  107. [download_image_name] ASC
  108. )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  109. ) ON [PRIMARY]
  110. GO
  111. /****** Object: Table [dbo].[enterprise] Script Date: 2017-05-29 15:54:12 ******/
  112. SET ANSI_NULLS ON
  113. GO
  114. SET QUOTED_IDENTIFIER ON
  115. GO
  116. CREATE TABLE [dbo].[enterprise](
  117. [industry_id] [nvarchar](4) NOT NULL,
  118. [enterprise_id] [nvarchar](10) NOT NULL,
  119. [enterprise_name] [nvarchar](64) NOT NULL,
  120. [enterprise_address] [nvarchar](128) NULL,
  121. [legal_person] [nvarchar](32) NULL,
  122. [company_website] [nvarchar](255) NULL,
  123. [corporate_phone] [nvarchar](32) NULL,
  124. [enterprise_note] [nvarchar](255) NULL,
  125. [access_key_id] [nvarchar](32) NULL,
  126. [access_key_secret] [nvarchar](64) NULL,
  127. [dndpoint] [nvarchar](128) NULL,
  128. [bucket_name] [nvarchar](36) NULL,
  129. CONSTRAINT [PK_enterprise] PRIMARY KEY CLUSTERED
  130. (
  131. [enterprise_id] ASC
  132. )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
  133. CONSTRAINT [UQ_enterprise_name] UNIQUE NONCLUSTERED
  134. (
  135. [enterprise_name] ASC
  136. )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  137. ) ON [PRIMARY]
  138. GO
  139. /****** Object: Table [dbo].[industry] Script Date: 2017-05-29 15:54:12 ******/
  140. SET ANSI_NULLS ON
  141. GO
  142. SET QUOTED_IDENTIFIER ON
  143. GO
  144. CREATE TABLE [dbo].[industry](
  145. [industry_id] [nvarchar](4) NOT NULL,
  146. [industry_name] [nvarchar](32) NOT NULL,
  147. [industry_note] [nvarchar](255) NULL,
  148. CONSTRAINT [PK_industry] PRIMARY KEY CLUSTERED
  149. (
  150. [industry_id] ASC
  151. )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
  152. CONSTRAINT [UQ_industry_name] UNIQUE NONCLUSTERED
  153. (
  154. [industry_name] ASC
  155. )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  156. ) ON [PRIMARY]
  157. GO
  158. /****** Object: Table [dbo].[recharge_record] Script Date: 2017-05-29 15:54:12 ******/
  159. SET ANSI_NULLS ON
  160. GO
  161. SET QUOTED_IDENTIFIER ON
  162. GO
  163. CREATE TABLE [dbo].[recharge_record](
  164. [branch_id] [nvarchar](32) NOT NULL,
  165. [recharge_datetime] [nvarchar](32) NOT NULL,
  166. [recharge_money] [money] NOT NULL,
  167. [recharge_flow] [bigint] NOT NULL,
  168. [recharge_note] [nvarchar](255) NULL,
  169. [charges_type] [smallint] NOT NULL,
  170. [recharge_month] [int] NOT NULL
  171. ) ON [PRIMARY]
  172. GO
  173. /****** Object: Table [dbo].[system_config] Script Date: 2017-05-29 15:54:12 ******/
  174. SET ANSI_NULLS ON
  175. GO
  176. SET QUOTED_IDENTIFIER ON
  177. GO
  178. CREATE TABLE [dbo].[system_config](
  179. [system_config_id] [int] IDENTITY(1,1) NOT NULL,
  180. [system_config_key] [nvarchar](255) NOT NULL,
  181. [system_config_value] [nvarchar](255) NULL,
  182. CONSTRAINT [PK_system_config] PRIMARY KEY CLUSTERED
  183. (
  184. [system_config_id] ASC,
  185. [system_config_key] ASC
  186. )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  187. ) ON [PRIMARY]
  188. GO
  189. /****** Object: Table [dbo].[upload_order] Script Date: 2017-05-29 15:54:12 ******/
  190. SET ANSI_NULLS ON
  191. GO
  192. SET QUOTED_IDENTIFIER ON
  193. GO
  194. CREATE TABLE [dbo].[upload_order](
  195. [upload_id] [nvarchar](64) NOT NULL,
  196. [upload_datetime] [nvarchar](32) NOT NULL,
  197. [upload_branch_id] [nvarchar](32) NOT NULL,
  198. [download_branch_id] [nvarchar](32) NOT NULL,
  199. [upload_image_type] [smallint] NOT NULL,
  200. [upload_order] [nvarchar](32) NOT NULL,
  201. [upload_images] [nvarchar](max) NOT NULL,
  202. [upload_status] [smallint] NOT NULL,
  203. [auto_download] [bit] NOT NULL,
  204. [download_storage_dir] [nvarchar](255) NULL,
  205. [download_status] [smallint] NOT NULL,
  206. CONSTRAINT [PK_upload_order] PRIMARY KEY CLUSTERED
  207. (
  208. [upload_id] ASC
  209. )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  210. ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
  211. GO
  212. /****** Object: Table [dbo].[uploaded_image] Script Date: 2017-05-29 15:54:12 ******/
  213. SET ANSI_NULLS ON
  214. GO
  215. SET QUOTED_IDENTIFIER ON
  216. GO
  217. CREATE TABLE [dbo].[uploaded_image](
  218. [upload_id] [nvarchar](50) NOT NULL,
  219. [upload_branch_id] [nvarchar](15) NOT NULL,
  220. [upload_image_name] [nvarchar](255) NOT NULL,
  221. [upload_key] [nvarchar](64) NOT NULL,
  222. [upload_image_size] [int] NOT NULL,
  223. [upload_datetime] [nvarchar](32) NOT NULL,
  224. [download_times] [int] NOT NULL,
  225. CONSTRAINT [PK_uploaded_image] PRIMARY KEY CLUSTERED
  226. (
  227. [upload_id] ASC,
  228. [upload_image_name] ASC
  229. )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  230. ) ON [PRIMARY]
  231. GO
  232. /****** Object: View [dbo].[branch_detail] Script Date: 2017-05-29 15:54:12 ******/
  233. SET ANSI_NULLS ON
  234. GO
  235. SET QUOTED_IDENTIFIER ON
  236. GO
  237. CREATE VIEW [dbo].[branch_detail]
  238. AS
  239. SELECT dbo.industry.industry_id, dbo.industry.industry_name, dbo.enterprise.enterprise_id,
  240. dbo.enterprise.enterprise_name, dbo.branch.head_office, dbo.branch.branch_id,
  241. dbo.branch.branch_name, dbo.branch.branch_phone,
  242. dbo.branch.branch_superintendent, dbo.branch.branch_address,
  243. dbo.branch.branch_account, dbo.branch.branch_password,
  244. dbo.branch.residual_flow, dbo.branch.branch_note, dbo.branch.charges_type,
  245. dbo.branch.date_of_expiry
  246. FROM dbo.branch INNER JOIN
  247. dbo.enterprise ON dbo.branch.enterprise_id = dbo.enterprise.enterprise_id INNER JOIN
  248. dbo.industry ON dbo.enterprise.industry_id = dbo.industry.industry_id
  249. GO
  250. /****** Object: View [dbo].[enterprise_detail] Script Date: 2017-05-29 15:54:12 ******/
  251. SET ANSI_NULLS ON
  252. GO
  253. SET QUOTED_IDENTIFIER ON
  254. GO
  255. CREATE VIEW [dbo].[enterprise_detail]
  256. AS
  257. SELECT
  258. dbo.industry.industry_id,
  259. dbo.industry.industry_name,
  260. dbo.enterprise.enterprise_id,
  261. dbo.enterprise.enterprise_name,
  262. dbo.enterprise.enterprise_address,
  263. dbo.enterprise.legal_person,
  264. dbo.enterprise.company_website,
  265. dbo.enterprise.corporate_phone,
  266. dbo.enterprise.access_key_id,
  267. dbo.enterprise.access_key_secret,
  268. dbo.enterprise.dndpoint,
  269. dbo.enterprise.bucket_name,
  270. dbo.enterprise.enterprise_note
  271. FROM dbo.industry INNER JOIN
  272. dbo.enterprise ON dbo.industry.industry_id = dbo.enterprise.industry_id
  273. GO
  274. /****** Object: View [dbo].[need_download] Script Date: 2017-05-29 15:54:12 ******/
  275. SET ANSI_NULLS ON
  276. GO
  277. SET QUOTED_IDENTIFIER ON
  278. GO
  279. CREATE VIEW [dbo].[need_download]
  280. AS
  281. with myexcept
  282. as
  283. (
  284. select upload_id,upload_image_name from uploaded_image except select upload_id,download_image_name from downloaded_image
  285. )
  286. select * from uploaded_image where upload_image_name in (select upload_image_name from myexcept)
  287. GO
  288. /****** Object: View [dbo].[recharge_detail] Script Date: 2017-05-29 15:54:12 ******/
  289. SET ANSI_NULLS ON
  290. GO
  291. SET QUOTED_IDENTIFIER ON
  292. GO
  293. CREATE VIEW [dbo].[recharge_detail]
  294. AS
  295. SELECT
  296. dbo.industry.industry_id,
  297. dbo.industry.industry_name,
  298. dbo.enterprise.enterprise_id,
  299. dbo.enterprise.enterprise_name,
  300. dbo.branch.branch_id,
  301. dbo.branch.branch_name,
  302. dbo.recharge_record.recharge_datetime,
  303. dbo.recharge_record.recharge_money,
  304. dbo.recharge_record.recharge_flow,
  305. dbo.recharge_record.recharge_note,
  306. dbo.recharge_record.charges_type,
  307. dbo.recharge_record.recharge_month
  308. FROM dbo.recharge_record INNER JOIN
  309. dbo.branch ON dbo.recharge_record.branch_id = dbo.branch.branch_id INNER JOIN
  310. dbo.enterprise ON dbo.branch.enterprise_id = dbo.enterprise.enterprise_id INNER JOIN
  311. dbo.industry ON dbo.enterprise.industry_id = dbo.industry.industry_id
  312. GO
  313. /****** Object: View [dbo].[upload_order_detail] Script Date: 2017-05-29 15:54:12 ******/
  314. SET ANSI_NULLS ON
  315. GO
  316. SET QUOTED_IDENTIFIER ON
  317. GO
  318. CREATE VIEW [dbo].[upload_order_detail]
  319. AS
  320. select
  321. upload_order.upload_id,
  322. upload_order.upload_branch_id,
  323. substring(upload_order.upload_branch_id,0,10) as upload_enterprise_id,
  324. (select enterprise_name from enterprise where enterprise.enterprise_id = substring(upload_order.upload_branch_id,0,10) )as upload_enterprise_name,
  325. (select branch_name from branch where branch.branch_id = upload_order.upload_branch_id)as upload_branch_name,
  326. upload_order.download_branch_id,
  327. substring(upload_order.download_branch_id,0,10) as download_enterprise_id,
  328. (select enterprise_name from enterprise where enterprise.enterprise_id = substring(upload_order.download_branch_id,0,10) )as download_enterprise_name,
  329. (select branch_name from branch where branch.branch_id = upload_order.download_branch_id)as download_branch_name,
  330. upload_order.upload_image_type,
  331. upload_order.upload_order,
  332. upload_order.upload_images,
  333. upload_order.upload_status,
  334. upload_order.upload_datetime,
  335. upload_order.auto_download,
  336. upload_order.download_storage_dir,
  337. upload_order.download_status
  338. from upload_order
  339. GO
  340. ALTER TABLE [dbo].[branch] ADD CONSTRAINT [DF_branch_charges_type] DEFAULT ((0)) FOR [charges_type]
  341. GO
  342. ALTER TABLE [dbo].[recharge_record] ADD CONSTRAINT [DF_tbl_recharge_RechargeMonth] DEFAULT ((0)) FOR [recharge_month]
  343. GO
  344. ALTER TABLE [dbo].[uploaded_image] ADD CONSTRAINT [DF__tbl_uploa__Downl__1367E606] DEFAULT ((0)) FOR [download_times]
  345. GO
  346. ALTER TABLE [dbo].[branch] WITH CHECK ADD CONSTRAINT [FK_enterprise_id] FOREIGN KEY([enterprise_id])
  347. REFERENCES [dbo].[enterprise] ([enterprise_id])
  348. GO
  349. ALTER TABLE [dbo].[branch] CHECK CONSTRAINT [FK_enterprise_id]
  350. GO
  351. ALTER TABLE [dbo].[enterprise] WITH CHECK ADD CONSTRAINT [FK_industry_id] FOREIGN KEY([industry_id])
  352. REFERENCES [dbo].[industry] ([industry_id])
  353. GO
  354. ALTER TABLE [dbo].[enterprise] CHECK CONSTRAINT [FK_industry_id]
  355. GO
  356. USE [master]
  357. GO
  358. ALTER DATABASE [lyfzems] SET READ_WRITE
  359. GO