summaryrefslogtreecommitdiff
path: root/sql/DB2-tables.sql
blob: 3ac7799971ce3dee5524b3f70721152aeb1981bb (plain)
  1. -- DB2-tables.sql
  2. -- Bill Ott modified from Oracle tables, March 02, 2002
  3. --
  4. -- Jim Rawlings modified for use with SL 2.0.8 and DB2 v7.2
  5. -- and higher August 27, 2003
  6. --
  7. --
  8. ---------------------------------------------------------
  9. -- DDL Statements for sequence id
  10. ---------------------------------------------------------
  11. CREATE SEQUENCE id AS INTEGER START WITH 10000
  12. INCREMENT BY 1 MAXVALUE 2147483647 MINVALUE 1 CACHE 5
  13. @
  14. ---------------------------------------------------------
  15. -- DDL Statements for table makemodel
  16. ---------------------------------------------------------
  17. CREATE TABLE makemodel (
  18. parts_id INTEGER,
  19. name VARCHAR(100)
  20. ) IN LEDGER_TS
  21. @
  22. ---------------------------------------------------------
  23. -- DDL Statements for table gl
  24. ---------------------------------------------------------
  25. CREATE TABLE gl (
  26. id INTEGER,
  27. reference VARCHAR(50),
  28. description VARCHAR(100),
  29. transdate DATE WITH DEFAULT current date,
  30. employee_id INTEGER,
  31. notes VARCHAR(4000)
  32. ) IN LEDGER_TS
  33. @
  34. ---------------------------------------------------------
  35. -- DDL Statements for table chart
  36. ---------------------------------------------------------
  37. CREATE TABLE chart (
  38. id INTEGER,
  39. accno VARCHAR(20) NOT NULL,
  40. description VARCHAR(100),
  41. charttype CHAR(1) WITH DEFAULT 'A',
  42. category CHAR(1),
  43. link VARCHAR(100),
  44. gifi_accno VARCHAR(20)
  45. ) IN LEDGER_TS
  46. @
  47. ---------------------------------------------------------
  48. -- DDL Statements for table gifi
  49. ---------------------------------------------------------
  50. CREATE TABLE gifi (
  51. accno VARCHAR(20),
  52. description VARCHAR(100)
  53. ) IN LEDGER_TS
  54. @
  55. ---------------------------------------------------------
  56. -- DDL Statements for table defaults
  57. ---------------------------------------------------------
  58. CREATE TABLE defaults (
  59. inventory_accno_id INTEGER,
  60. income_accno_id INTEGER,
  61. expense_accno_id INTEGER,
  62. fxgain_accno_id INTEGER,
  63. fxloss_accno_id INTEGER,
  64. invnumber VARCHAR(30),
  65. sonumber VARCHAR(30),
  66. yearend VARCHAR(5),
  67. weightunit VARCHAR(5),
  68. businessnumber VARCHAR(30),
  69. version VARCHAR(8),
  70. curr VARCHAR(500),
  71. closedto DATE,
  72. revtrans CHAR(1) WITH DEFAULT '0',
  73. ponumber VARCHAR(30)
  74. ) IN LEDGER_TS
  75. @
  76. INSERT INTO defaults (version) VALUES ('2.0.10')
  77. @
  78. ---------------------------------------------------------
  79. -- DDL Statements for table acc_trans
  80. ---------------------------------------------------------
  81. CREATE TABLE acc_trans (
  82. trans_id INTEGER,
  83. chart_id INTEGER,
  84. amount FLOAT,
  85. transdate DATE WITH DEFAULT current date,
  86. source VARCHAR(20),
  87. cleared CHAR(1) WITH DEFAULT '0',
  88. fx_transaction CHAR(1) WITH DEFAULT '0',
  89. project_id INTEGER
  90. ) IN LEDGER_TS
  91. @
  92. ---------------------------------------------------------
  93. -- DDL Statements for table invoice
  94. ---------------------------------------------------------
  95. CREATE TABLE invoice (
  96. id INTEGER,
  97. trans_id INTEGER,
  98. parts_id INTEGER,
  99. description VARCHAR(4000),
  100. qty FLOAT,
  101. allocated FLOAT,
  102. sellprice FLOAT,
  103. fxsellprice FLOAT,
  104. discount FLOAT,
  105. assemblyitem CHAR(1) WITH DEFAULT '0',
  106. unit VARCHAR(5),
  107. project_id INTEGER,
  108. deliverydate DATE
  109. ) IN LEDGER_TS
  110. @
  111. ---------------------------------------------------------
  112. -- DDL Statements for table vendor
  113. ---------------------------------------------------------
  114. CREATE TABLE vendor (
  115. id INTEGER,
  116. name VARCHAR(35),
  117. addr1 VARCHAR(35),
  118. addr2 VARCHAR(35),
  119. addr3 VARCHAR(35),
  120. addr4 VARCHAR(35),
  121. contact VARCHAR(35),
  122. phone VARCHAR(20),
  123. fax VARCHAR(20),
  124. email VARCHAR(50),
  125. notes VARCHAR(4000),
  126. terms INTEGER WITH DEFAULT,
  127. taxincluded CHAR(1),
  128. vendornumber VARCHAR(40),
  129. cc VARCHAR(50),
  130. bcc VARCHAR(50)
  131. ) IN LEDGER_TS
  132. @
  133. ---------------------------------------------------------
  134. -- DDL Statements for table customer
  135. ---------------------------------------------------------
  136. CREATE TABLE customer (
  137. id INTEGER,
  138. name VARCHAR(35),
  139. addr1 VARCHAR(35),
  140. addr2 VARCHAR(35),
  141. addr3 VARCHAR(35),
  142. addr4 VARCHAR(35),
  143. contact VARCHAR(35),
  144. phone VARCHAR(20),
  145. fax VARCHAR(20),
  146. email VARCHAR(50),
  147. notes VARCHAR(4000),
  148. discount FLOAT,
  149. taxincluded CHAR(1),
  150. creditlimit FLOAT,
  151. terms INTEGER WITH DEFAULT,
  152. customernumber VARCHAR(40),
  153. cc VARCHAR(50),
  154. bcc VARCHAR(50)
  155. ) IN LEDGER_TS
  156. @
  157. ---------------------------------------------------------
  158. -- DDL Statements for table parts
  159. ---------------------------------------------------------
  160. CREATE TABLE parts (
  161. id INTEGER,
  162. partnumber VARCHAR(30),
  163. description VARCHAR(4000),
  164. unit VARCHAR(5),
  165. listprice FLOAT,
  166. sellprice FLOAT,
  167. lastcost FLOAT,
  168. priceupdate DATE WITH DEFAULT current date,
  169. weight FLOAT,
  170. onhand FLOAT WITH DEFAULT 0,
  171. notes VARCHAR(1500),
  172. makemodel CHAR(1) WITH DEFAULT '0',
  173. assembly CHAR(1) WITH DEFAULT '0',
  174. alternate CHAR(1) WITH DEFAULT '0',
  175. rop FLOAT,
  176. inventory_accno_id INTEGER,
  177. income_accno_id INTEGER,
  178. expense_accno_id INTEGER,
  179. bin VARCHAR(20),
  180. obsolete CHAR(1) WITH DEFAULT '0',
  181. bom CHAR(1) WITH DEFAULT '0',
  182. image VARCHAR(100),
  183. drawing VARCHAR(100),
  184. microfiche VARCHAR(100),
  185. partsgroup_id INTEGER
  186. ) IN LEDGER_TS
  187. @
  188. ---------------------------------------------------------
  189. -- DDL Statements for table assembly
  190. ---------------------------------------------------------
  191. CREATE TABLE assembly (
  192. id INTEGER,
  193. parts_id INTEGER,
  194. qty FLOAT,
  195. bom CHAR(1)
  196. ) IN LEDGER_TS
  197. @
  198. ---------------------------------------------------------
  199. -- DDL Statements for table ar
  200. ---------------------------------------------------------
  201. CREATE TABLE ar (
  202. id INTEGER,
  203. invnumber VARCHAR(30),
  204. transdate DATE WITH DEFAULT current date,
  205. customer_id INTEGER,
  206. taxincluded CHAR(1),
  207. amount FLOAT,
  208. netamount FLOAT,
  209. paid FLOAT,
  210. datepaid DATE,
  211. duedate DATE,
  212. invoice CHAR(1) WITH DEFAULT '0',
  213. shippingpoint VARCHAR(100),
  214. terms INTEGER WITH DEFAULT 0,
  215. notes VARCHAR(4000),
  216. curr CHAR(3),
  217. ordnumber VARCHAR(30),
  218. employee_id INTEGER
  219. ) IN LEDGER_TS
  220. @
  221. ---------------------------------------------------------
  222. -- DDL Statements for table ap
  223. ---------------------------------------------------------
  224. CREATE TABLE ap (
  225. id INTEGER,
  226. invnumber VARCHAR(30),
  227. transdate DATE WITH DEFAULT current date,
  228. vendor_id INTEGER,
  229. taxincluded CHAR(1) WITH DEFAULT '0',
  230. amount FLOAT,
  231. netamount FLOAT,
  232. paid FLOAT,
  233. datepaid DATE,
  234. duedate DATE,
  235. invoice CHAR(1) WITH DEFAULT '0',
  236. ordnumber VARCHAR(30),
  237. curr CHAR(3),
  238. notes VARCHAR(4000),
  239. employee_id INTEGER
  240. ) IN LEDGER_TS
  241. @
  242. ---------------------------------------------------------
  243. -- DDL Statements for table partstax
  244. ---------------------------------------------------------
  245. CREATE TABLE partstax (
  246. parts_id INTEGER,
  247. chart_id INTEGER
  248. ) IN LEDGER_TS
  249. @
  250. ---------------------------------------------------------
  251. -- DDL Statements for table tax
  252. ---------------------------------------------------------
  253. CREATE TABLE tax (
  254. chart_id INTEGER,
  255. rate FLOAT,
  256. taxnumber VARCHAR(30)
  257. ) IN LEDGER_TS
  258. @
  259. ---------------------------------------------------------
  260. -- DDL Statements for table customertax
  261. ---------------------------------------------------------
  262. CREATE TABLE customertax (
  263. customer_id INTEGER,
  264. chart_id INTEGER
  265. ) IN LEDGER_TS
  266. @
  267. ---------------------------------------------------------
  268. -- DDL Statements for table vendortax
  269. ---------------------------------------------------------
  270. CREATE TABLE vendortax (
  271. vendor_id INTEGER,
  272. chart_id INTEGER
  273. ) IN LEDGER_TS
  274. @
  275. ---------------------------------------------------------
  276. -- DDL Statements for table oe
  277. ---------------------------------------------------------
  278. CREATE TABLE oe (
  279. id INTEGER,
  280. ordnumber VARCHAR(30),
  281. transdate DATE WITH DEFAULT current date,
  282. vendor_id INTEGER,
  283. customer_id INTEGER,
  284. amount FLOAT,
  285. netamount FLOAT,
  286. reqdate DATE,
  287. taxincluded CHAR(1),
  288. shippingpoint VARCHAR(100),
  289. notes VARCHAR(4000),
  290. curr CHAR(3),
  291. employee_id INTEGER,
  292. closed CHAR(1) WITH DEFAULT '0'
  293. ) IN LEDGER_TS
  294. @
  295. ---------------------------------------------------------
  296. -- DDL Statements for table orderitems
  297. ---------------------------------------------------------
  298. CREATE TABLE orderitems (
  299. trans_id INTEGER,
  300. parts_id INTEGER,
  301. description VARCHAR(4000),
  302. qty FLOAT,
  303. sellprice FLOAT,
  304. discount FLOAT,
  305. unit VARCHAR(5),
  306. project_id INTEGER,
  307. reqdate DATE
  308. ) IN LEDGER_TS
  309. @
  310. ---------------------------------------------------------
  311. -- DDL Statements for table exchangerate
  312. ---------------------------------------------------------
  313. CREATE TABLE exchangerate (
  314. curr CHAR(3),
  315. transdate DATE,
  316. buy FLOAT,
  317. sell FLOAT
  318. ) IN LEDGER_TS
  319. @
  320. ---------------------------------------------------------
  321. -- DDL Statements for table employee
  322. ---------------------------------------------------------
  323. CREATE TABLE employee (
  324. id INTEGER,
  325. login VARCHAR(20),
  326. name VARCHAR(35),
  327. addr1 VARCHAR(35),
  328. addr2 VARCHAR(35),
  329. addr3 VARCHAR(35),
  330. addr4 VARCHAR(35),
  331. workphone VARCHAR(20),
  332. homephone VARCHAR(20),
  333. startdate DATE WITH DEFAULT current date,
  334. enddate DATE,
  335. notes VARCHAR(4000)
  336. ) IN LEDGER_TS
  337. @
  338. ---------------------------------------------------------
  339. -- DDL Statements for table shipto
  340. ---------------------------------------------------------
  341. CREATE TABLE shipto (
  342. trans_id INTEGER,
  343. shiptoname VARCHAR(35),
  344. shiptoaddr1 VARCHAR(35),
  345. shiptoaddr2 VARCHAR(35),
  346. shiptoaddr3 VARCHAR(35),
  347. shiptoaddr4 VARCHAR(35),
  348. shiptocontact VARCHAR(35),
  349. shiptophone VARCHAR(20),
  350. shiptofax VARCHAR(20),
  351. shiptoemail VARCHAR(50)
  352. ) IN LEDGER_TS
  353. @
  354. ---------------------------------------------------------
  355. -- DDL Statements for table project
  356. ---------------------------------------------------------
  357. CREATE TABLE project (
  358. id INTEGER,
  359. projectnumber VARCHAR(50),
  360. description VARCHAR(4000)
  361. ) IN LEDGER_TS
  362. @
  363. ---------------------------------------------------------
  364. -- DDL Statements for table partsgroup
  365. ---------------------------------------------------------
  366. CREATE TABLE partsgroup (
  367. id INTEGER,
  368. partsgroup VARCHAR(100)
  369. ) IN LEDGER_TS
  370. @
  371. ---------------------------------------------------------
  372. --!#
  373. --!# functions N/A
  374. --!#
  375. ---------------------------------------------------------
  376. --!#
  377. --!# triggers
  378. --!#
  379. ---------------------------------------------------------
  380. -- DDL Statements for trigger glid
  381. ---------------------------------------------------------
  382. CREATE TRIGGER glid
  383. NO CASCADE BEFORE INSERT ON gl
  384. REFERENCING NEW AS new_id
  385. FOR EACH ROW MODE DB2SQL
  386. BEGIN ATOMIC
  387. set new_id.id = NEXTVAL FOR id;
  388. END
  389. @
  390. ---------------------------------------------------------
  391. -- DDL Statements for trigger chartid
  392. ---------------------------------------------------------
  393. CREATE TRIGGER chartid
  394. NO CASCADE BEFORE INSERT ON chart
  395. REFERENCING NEW AS new_id
  396. FOR EACH ROW MODE DB2SQL
  397. BEGIN ATOMIC
  398. set new_id.id = NEXTVAL FOR id;
  399. END
  400. @
  401. ---------------------------------------------------------
  402. -- DDL Statements for trigger invoiceid
  403. ---------------------------------------------------------
  404. CREATE TRIGGER invoiceid
  405. NO CASCADE BEFORE INSERT ON invoice
  406. REFERENCING NEW AS new_id
  407. FOR EACH ROW MODE DB2SQL
  408. BEGIN ATOMIC
  409. set new_id.id = NEXTVAL FOR id;
  410. END
  411. @
  412. ---------------------------------------------------------
  413. -- DDL Statements for trigger vendorid
  414. ---------------------------------------------------------
  415. CREATE TRIGGER vendorid
  416. NO CASCADE BEFORE INSERT ON vendor
  417. REFERENCING NEW AS new_id
  418. FOR EACH ROW MODE DB2SQL
  419. BEGIN ATOMIC
  420. set new_id.id = NEXTVAL FOR id;
  421. END
  422. @
  423. ---------------------------------------------------------
  424. -- DDL Statements for trigger customerid
  425. ---------------------------------------------------------
  426. CREATE TRIGGER customerid
  427. NO CASCADE BEFORE INSERT ON customer
  428. REFERENCING NEW AS new_id
  429. FOR EACH ROW MODE DB2SQL
  430. BEGIN ATOMIC
  431. set new_id.id = NEXTVAL FOR id;
  432. END
  433. @
  434. ---------------------------------------------------------
  435. -- DDL Statements for trigger partsid
  436. ---------------------------------------------------------
  437. CREATE TRIGGER partsid
  438. NO CASCADE BEFORE INSERT ON parts
  439. REFERENCING NEW AS new_id
  440. FOR EACH ROW MODE DB2SQL
  441. BEGIN ATOMIC
  442. set new_id.id = NEXTVAL FOR id;
  443. END
  444. @
  445. ---------------------------------------------------------
  446. -- DDL Statements for trigger arid
  447. ---------------------------------------------------------
  448. CREATE TRIGGER arid
  449. NO CASCADE BEFORE INSERT ON ar
  450. REFERENCING NEW AS new_id
  451. FOR EACH ROW MODE DB2SQL
  452. BEGIN ATOMIC
  453. set new_id.id = NEXTVAL FOR id;
  454. END
  455. @
  456. ---------------------------------------------------------
  457. -- DDL Statements for trigger apid
  458. ---------------------------------------------------------
  459. CREATE TRIGGER apid
  460. NO CASCADE BEFORE INSERT ON ap
  461. REFERENCING NEW AS new_id
  462. FOR EACH ROW MODE DB2SQL
  463. BEGIN ATOMIC
  464. set new_id.id = NEXTVAL FOR id;
  465. END
  466. @
  467. ---------------------------------------------------------
  468. -- DDL Statements for trigger oeid
  469. ---------------------------------------------------------
  470. CREATE TRIGGER oeid
  471. NO CASCADE BEFORE INSERT ON oe
  472. REFERENCING NEW AS new_id
  473. FOR EACH ROW MODE DB2SQL
  474. BEGIN ATOMIC
  475. set new_id.id = NEXTVAL FOR id;
  476. END
  477. @
  478. ---------------------------------------------------------
  479. -- DDL Statements for trigger employeeid
  480. ---------------------------------------------------------
  481. CREATE TRIGGER employeeid
  482. NO CASCADE BEFORE INSERT ON employee
  483. REFERENCING NEW AS new_id
  484. FOR EACH ROW MODE DB2SQL
  485. BEGIN ATOMIC
  486. set new_id.id = NEXTVAL FOR id;
  487. END
  488. @
  489. ---------------------------------------------------------
  490. -- DDL Statements for trigger projectid
  491. ---------------------------------------------------------
  492. CREATE TRIGGER projectid
  493. NO CASCADE BEFORE INSERT ON project
  494. REFERENCING NEW AS new_id
  495. FOR EACH ROW MODE DB2SQL
  496. BEGIN ATOMIC
  497. set new_id.id = NEXTVAL FOR id;
  498. END
  499. @
  500. ---------------------------------------------------------
  501. -- DDL Statements for trigger partsgroupid
  502. ---------------------------------------------------------
  503. CREATE TRIGGER partsgroupid
  504. NO CASCADE BEFORE INSERT ON partsgroup
  505. REFERENCING NEW AS new_id
  506. FOR EACH ROW MODE DB2SQL
  507. BEGIN ATOMIC
  508. set new_id.id = NEXTVAL FOR id;
  509. END@