home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a025 / 8.ddi / INSTPUBS.SQ@ / INSTPUBS.bin
Encoding:
Text File  |  1992-09-15  |  23.3 KB  |  950 lines

  1.  
  2. /* $Header:   S:/DBMS/OS2/SCRIPTS/PVCS/INSTPUBS.SQV   4.1   18 Feb 1992 14:30:50   DANY  $ */
  3. /* has primary and foreign keys*/
  4. set nocount on
  5.  
  6. if exists (select * from master.dbo.sysdatabases
  7.         where name = "pubs")
  8. begin
  9.     drop database pubs
  10. end
  11. go
  12. print 'Creating the "pubs" database'
  13. create database pubs
  14. go
  15. set dateformat mdy
  16. go
  17. use pubs
  18. go
  19. if exists (select * from master.dbo.sysdatabases
  20.         where name = "pubs")
  21. begin
  22.     execute sp_addtype id, "varchar(11)", "not null"
  23.     execute sp_addtype tid, "varchar(6)", "not null"
  24. end
  25. go
  26. if exists (select * from master.dbo.sysdatabases
  27.         where name = "pubs")
  28. begin
  29.     create table authors
  30.     (au_id id,
  31.     au_lname varchar(40) not null,
  32.     au_fname varchar(20) not null,
  33.     phone char(12),
  34.     address varchar(40) null,
  35.     city varchar(20) null,
  36.     state char(2) null,
  37.     zip char(5) null,
  38.     contract bit)
  39. end
  40. go
  41. grant select on authors to public
  42. go
  43. if exists (select * from master.dbo.sysdatabases
  44.         where name = "pubs")
  45. begin
  46.     create table publishers
  47.     (pub_id char(4) not null,
  48.     pub_name varchar(40) null,
  49.     city varchar(20) null,
  50.     state char(2) null)
  51. end
  52. go
  53. grant select on publishers to public
  54. go
  55. if exists (select * from master.dbo.sysdatabases
  56.         where name = "pubs")
  57. begin
  58.     create table roysched
  59.     (title_id tid,
  60.     lorange int null,
  61.     hirange int null,
  62.     royalty int null)
  63. end
  64. go
  65. grant select on roysched to public
  66. go
  67. if exists (select * from master.dbo.sysdatabases
  68.         where name = "pubs")
  69. begin
  70.     create table sales
  71.     (stor_id char(4),
  72.     ord_num varchar(20),
  73.     date datetime,
  74.     qty smallint,
  75.     payterms varchar(12),
  76.     title_id tid)
  77. end
  78. go
  79. grant select on sales to public
  80. go
  81. if exists (select * from master.dbo.sysdatabases
  82.         where name = "pubs")
  83. begin
  84.     create table titleauthor
  85.     (au_id id,
  86.     title_id tid,
  87.     au_ord tinyint null,
  88.     royaltyper int null)
  89. end
  90. go
  91. grant select on titleauthor to public
  92. go
  93. if exists (select * from master.dbo.sysdatabases
  94.         where name = "pubs")
  95. begin
  96.     create table titles
  97.     (title_id tid,
  98.     title varchar(80) not null,
  99.     type char(12),
  100.     pub_id char(4) null,
  101.     price money null,
  102.     advance money null,
  103.     royalty int null,
  104.     ytd_sales int null,
  105.     notes varchar(200) null,
  106.     pubdate datetime)
  107. end
  108. go
  109. grant select on titles to public
  110. go
  111. if exists (select * from master.dbo.sysdatabases
  112.         where name = "pubs")
  113. begin
  114.     create table stores
  115.     (stor_id char(4),
  116.     stor_name varchar(40) null,
  117.     stor_address varchar(40) null,
  118.     city varchar(20) null,
  119.     state char(2) null,
  120.     zip char(5) null)
  121. end
  122. go
  123. grant select on stores to public
  124. go
  125. if exists (select * from master.dbo.sysdatabases
  126.         where name = "pubs")
  127. begin
  128.     create table discounts
  129.     (discounttype   varchar(40) not null,
  130.     stor_id         char(4) null,
  131.     lowqty          smallint null,
  132.     highqty         smallint null,
  133.     discount        float)
  134. end
  135. go
  136. grant select on discounts to public
  137. go
  138. create default typedflt
  139. as "UNDECIDED"
  140. go
  141. sp_bindefault typedflt, "titles.type"
  142. go
  143. create default datedflt
  144. as getdate()
  145. go
  146. sp_bindefault datedflt, "titles.pubdate"
  147. go
  148. create default phonedflt
  149. as "UNKNOWN"
  150. go
  151. sp_bindefault phonedflt, "authors.phone"
  152. go
  153. insert authors
  154. values('409-56-7008', 'Bennet', 'Abraham',
  155. '415 658-9932', '6223 Bateman St.', 'Berkeley', 'CA', '94705', 1)
  156. go
  157. insert authors
  158. values ('213-46-8915', 'Green', 'Marjorie',
  159. '415 986-7020', '309 63rd St. #411', 'Oakland', 'CA', '94618', 1)
  160. go
  161. insert authors
  162. values('238-95-7766', 'Carson', 'Cheryl',
  163. '415 548-7723', '589 Darwin Ln.', 'Berkeley', 'CA', '94705', 1)
  164. go
  165. insert authors
  166. values('998-72-3567', 'Ringer', 'Albert',
  167. '801 826-0752', '67 Seventh Av.', 'Salt Lake City', 'UT', '84152', 1)
  168. go
  169. insert authors
  170. values('899-46-2035', 'Ringer', 'Anne',
  171. '801 826-0752', '67 Seventh Av.', 'Salt Lake City', 'UT', '84152', 1)
  172. go
  173. insert authors
  174. values('722-51-5454', 'DeFrance', 'Michel',
  175. '219 547-9982', '3 Balding Pl.', 'Gary', 'IN', '46403', 1)
  176. go
  177. insert authors
  178. values('807-91-6654', 'Panteley', 'Sylvia',
  179. '301 946-8853', '1956 Arlington Pl.', 'Rockville', 'MD', '20853', 1)
  180. go
  181. insert authors
  182. values('893-72-1158', 'McBadden', 'Heather',
  183. '707 448-4982', '301 Putnam', 'Vacaville', 'CA', '95688', 0)
  184. go
  185. insert authors
  186. values('724-08-9931', 'Stringer', 'Dirk',
  187. '415 843-2991', '5420 Telegraph Av.', 'Oakland', 'CA', '94609', 0)
  188. go
  189. insert authors
  190. values('274-80-9391', 'Straight', 'Dean',
  191. '415 834-2919', '5420 College Av.', 'Oakland', 'CA', '94609', 1)
  192. go
  193. insert authors
  194. values('756-30-7391', 'Karsen', 'Livia',
  195. '415 534-9219', '5720 McAuley St.', 'Oakland', 'CA', '94609', 1)
  196. go
  197. insert authors
  198. values('724-80-9391', 'MacFeather', 'Stearns',
  199. '415 354-7128', '44 Upland Hts.', 'Oakland', 'CA', '94612', 1)
  200. go
  201. insert authors
  202. values('427-17-2319', 'Dull', 'Ann',
  203. '415 836-7128', '3410 Blonde St.', 'Palo Alto', 'CA', '94301', 1)
  204. go
  205. insert authors
  206. values('672-71-3249', 'Yokomoto', 'Akiko',
  207. '415 935-4228', '3 Silver Ct.', 'Walnut Creek', 'CA', '94595', 1)
  208. go
  209. insert authors
  210. values('267-41-2394', "O'Leary", 'Michael',
  211. '408 286-2428', '22 Cleveland Av. #14', 'San Jose', 'CA', '95128', 1)
  212. go
  213. insert authors
  214. values('472-27-2349', 'Gringlesby', 'Burt',
  215. '707 938-6445', 'PO Box 792', 'Covelo', 'CA', '95428', 3)
  216. go
  217. insert authors
  218. values('527-72-3246', 'Greene', 'Morningstar',
  219. '615 297-2723', '22 Graybar House Rd.', 'Nashville', 'TN', '37215', 0)
  220. go
  221. insert authors
  222. values('172-32-1176', 'White', 'Johnson',
  223. '408 496-7223', '10932 Bigge Rd.', 'Menlo Park', 'CA', '94025', 1)
  224. go
  225. insert authors
  226. values('712-45-1867', 'del Castillo', 'Innes',
  227. '615 996-8275', '2286 Cram Pl. #86', 'Ann Arbor', 'MI', '48105', 1)
  228. go
  229. insert authors
  230. values('846-92-7186', 'Hunter', 'Sheryl',
  231. '415 836-7128', '3410 Blonde St.', 'Palo Alto', 'CA', '94301', 1)
  232. go
  233. insert authors
  234. values('486-29-1786', 'Locksley', 'Charlene',
  235. '415 585-4620', '18 Broadway Av.', 'San Francisco', 'CA', '94130', 1)
  236. go
  237. insert authors
  238. values('648-92-1872', 'Blotchet-Halls', 'Reginald',
  239. '503 745-6402', '55 Hillsdale Bl.', 'Corvallis', 'OR', '97330', 1)
  240. go
  241. insert authors
  242. values('341-22-1782', 'Smith', 'Meander',
  243. '913 843-0462', '10 Mississippi Dr.', 'Lawrence', 'KS', '66044', 0)
  244. go
  245. insert publishers
  246. values('0736', 'New Moon Books', 'Boston', 'MA')
  247. go
  248. insert publishers
  249. values('0877', 'Binnet & Hardley', 'Washington', 'DC')
  250. go
  251. insert publishers
  252. values('1389', 'Algodata Infosystems', 'Berkeley', 'CA')
  253. go
  254. insert roysched
  255. values('BU1032', 0, 5000, 10)
  256. go
  257. insert roysched
  258. values('BU1032', 5001, 50000, 12)
  259. go
  260. insert roysched
  261. values('PC1035', 0, 2000, 10)
  262. go
  263. insert roysched
  264. values('PC1035', 2001, 3000, 12)
  265. go
  266. insert roysched
  267. values('PC1035', 3001, 4000, 14)
  268. go
  269. insert roysched
  270. values('PC1035', 4001, 10000, 16)
  271. go
  272. insert roysched
  273. values('PC1035', 10001, 50000, 18)
  274. go
  275. insert roysched
  276. values('BU2075', 0, 1000, 10)
  277. go
  278. insert roysched
  279. values('BU2075', 1001, 3000, 12)
  280. go
  281. insert roysched
  282. values('BU2075', 3001, 5000, 14)
  283. go
  284. insert roysched
  285. values('BU2075', 5001, 7000, 16)
  286. go
  287. insert roysched
  288. values('BU2075', 7001, 10000, 18)
  289. go
  290. insert roysched
  291. values('BU2075', 10001, 12000, 20)
  292. go
  293. insert roysched
  294. values('BU2075', 12001, 14000, 22)
  295. go
  296. insert roysched
  297. values('BU2075', 14001, 50000, 24)
  298. go
  299. insert roysched
  300. values('PS2091', 0, 1000, 10)
  301. go
  302. insert roysched
  303. values('PS2091', 1001, 5000, 12)
  304. go
  305. insert roysched
  306. values('PS2091', 5001, 10000, 14)
  307. go
  308. insert roysched
  309. values('PS2091', 10001, 50000, 16)
  310. go
  311. insert roysched
  312. values('PS2106', 0, 2000, 10)
  313. go
  314. insert roysched
  315. values('PS2106', 2001, 5000, 12)
  316. go
  317. insert roysched
  318. values('PS2106', 5001, 10000, 14)
  319. go
  320. insert roysched
  321. values('PS2106', 10001, 50000, 16)
  322. go
  323. insert roysched
  324. values('MC3021', 0, 1000, 10)
  325. go
  326. insert roysched
  327. values('MC3021', 1001, 2000, 12)
  328. go
  329. insert roysched
  330. values('MC3021', 2001, 4000, 14)
  331. go
  332. insert roysched
  333. values('MC3021', 4001, 6000, 16)
  334. go
  335. insert roysched
  336. values('MC3021', 6001, 8000, 18)
  337. go
  338. insert roysched
  339. values('MC3021', 8001, 10000, 20)
  340. go
  341. insert roysched
  342. values('MC3021', 10001, 12000, 22)
  343. go
  344. insert roysched
  345. values('MC3021', 12001, 50000, 24)
  346. go
  347. insert roysched
  348. values('TC3218', 0, 2000, 10)
  349. go
  350. insert roysched
  351. values('TC3218', 2001, 4000, 12)
  352. go
  353. insert roysched
  354. values('TC3218', 4001, 6000, 14)
  355. go
  356. insert roysched
  357. values('TC3218', 6001, 8000, 16)
  358. go
  359. insert roysched
  360. values('TC3218', 8001, 10000, 18)
  361. go
  362. insert roysched
  363. values('TC3218', 10001, 12000, 20)
  364. go
  365. insert roysched
  366. values('TC3218', 12001, 14000, 22)
  367. go
  368. insert roysched
  369. values('TC3218', 14001, 50000, 24)
  370. go
  371. insert roysched
  372. values('PC8888', 0, 5000, 10)
  373. go
  374. insert roysched
  375. values('PC8888', 5001, 10000, 12)
  376. go
  377. insert roysched
  378. values('PC8888', 10001, 15000, 14)
  379. go
  380. insert roysched
  381. values('PC8888', 15001, 50000, 16)
  382. go
  383. insert roysched
  384. values('PS7777', 0, 5000, 10)
  385. go
  386. insert roysched
  387. values('PS7777', 5001, 50000, 12)
  388. go
  389. insert roysched
  390. values('PS3333', 0, 5000, 10)
  391. go
  392. insert roysched
  393. values('PS3333', 5001, 10000, 12)
  394. go
  395. insert roysched
  396. values('PS3333', 10001, 15000, 14)
  397. go
  398. insert roysched
  399. values('PS3333', 15001, 50000, 16)
  400. go
  401. insert roysched
  402. values('BU1111', 0, 4000, 10)
  403. go
  404. insert roysched
  405. values('BU1111', 4001, 8000, 12)
  406. go
  407. insert roysched
  408. values('BU1111', 8001, 10000, 14)
  409. go
  410. insert roysched
  411. values('BU1111', 12001, 16000, 16)
  412. go
  413. insert roysched
  414. values('BU1111', 16001, 20000, 18)
  415. go
  416. insert roysched
  417. values('BU1111', 20001, 24000, 20)
  418. go
  419. insert roysched
  420. values('BU1111', 24001, 28000, 22)
  421. go
  422. insert roysched
  423. values('BU1111', 28001, 50000, 24)
  424. go
  425. insert roysched
  426. values('MC2222', 0, 2000, 10)
  427. go
  428. insert roysched
  429. values('MC2222', 2001, 4000, 12)
  430. go
  431. insert roysched
  432. values('MC2222', 4001, 8000, 14)
  433. go
  434. insert roysched
  435. values('MC2222', 8001, 12000, 16)
  436. go
  437. insert roysched
  438. values('MC2222', 8001, 12000, 16)
  439. go
  440. insert roysched
  441. values('MC2222', 12001, 20000, 18)
  442. go
  443. insert roysched
  444. values('MC2222', 20001, 50000, 20)
  445. go
  446. insert roysched
  447. values('TC7777', 0, 5000, 10)
  448. go
  449. insert roysched
  450. values('TC7777', 5001, 15000, 12)
  451. go
  452. insert roysched
  453. values('TC7777', 15001, 50000, 14)
  454. go
  455. insert roysched
  456. values('TC4203', 0, 2000, 10)
  457. go
  458. insert roysched
  459. values('TC4203', 2001, 8000, 12)
  460. go
  461. insert roysched
  462. values('TC4203', 8001, 16000, 14)
  463. go
  464. insert roysched
  465. values('TC4203', 16001, 24000, 16)
  466. go
  467. insert roysched
  468. values('TC4203', 24001, 32000, 18)
  469. go
  470. insert roysched
  471. values('TC4203', 32001, 40000, 20)
  472. go
  473. insert roysched
  474. values('TC4203', 40001, 50000, 22)
  475. go
  476. insert roysched
  477. values('BU7832', 0, 5000, 10)
  478. go
  479. insert roysched
  480. values('BU7832', 5001, 10000, 12)
  481. go
  482. insert roysched
  483. values('BU7832', 10001, 15000, 14)
  484. go
  485. insert roysched
  486. values('BU7832', 15001, 20000, 16)
  487. go
  488. insert roysched
  489. values('BU7832', 20001, 25000, 18)
  490. go
  491. insert roysched
  492. values('BU7832', 25001, 30000, 20)
  493. go
  494. insert roysched
  495. values('BU7832', 30001, 35000, 22)
  496. go
  497. insert roysched
  498. values('BU7832', 35001, 50000, 24)
  499. go
  500. insert roysched
  501. values('PS1372', 0, 10000, 10)
  502. go
  503. insert roysched
  504. values('PS1372', 10001, 20000, 12)
  505. go
  506. insert roysched
  507. values('PS1372', 20001, 30000, 14)
  508. go
  509. insert roysched
  510. values('PS1372', 30001, 40000, 16)
  511. go
  512. insert roysched
  513. values('PS1372', 40001, 50000, 18)
  514. go
  515. insert sales
  516. values('7066', 'QA7442.3', '09/13/85', 75, 'On invoice','PS2091')
  517. go
  518. insert sales
  519. values('7067', 'D4482', '09/14/85', 10, 'Net 60','PS2091')
  520. go
  521. insert sales
  522. values('7131', 'N914008', '09/14/85', 20, 'Net 30','PS2091')
  523. go
  524. insert sales
  525. values('7131', 'N914014', '09/14/85', 25, 'Net 30','MC3021')
  526. go
  527. insert sales
  528. values('8042', '423LL922', '09/14/85', 15, 'On invoice','MC3021')
  529. go
  530. insert sales
  531. values('8042', '423LL930', '09/14/85', 10, 'On invoice','BU1032')
  532. go
  533. insert sales
  534. values('6380', '722a', '09/13/85', 3, 'Net 60','PS2091')
  535. go
  536. insert sales
  537. values('6380', '6871', '09/14/85', 5, 'Net 60','BU1032')
  538. go
  539. insert sales
  540. values('8042','P723', '03/11/88', 25, 'Net 30', 'BU1111')
  541. go
  542. insert sales
  543. values('7896','X999', '02/21/88', 35, 'On invoice', 'BU2075')
  544. go
  545. insert sales
  546. values('7896','QQ2299', '10/28/87', 15, 'Net 60', 'BU7832')
  547. go
  548. insert sales
  549. values('7896','TQ456', '12/12/87', 10, 'Net 60', 'MC2222')
  550. go
  551. insert sales
  552. values('8042','QA879.1', '5/22/87', 30, 'Net 30', 'PC1035')
  553. go
  554. insert sales
  555. values('7066','A2976', '5/24/87', 50, 'Net 30', 'PC8888')
  556. go
  557. insert sales
  558. values('7131','P3087a', '5/29/87', 20, 'Net 60', 'PS1372')
  559. go
  560. insert sales
  561. values('7131','P3087a', '5/29/87', 25, 'Net 60', 'PS2106')
  562. go
  563. insert sales
  564. values('7131','P3087a', '5/29/87', 15, 'Net 60', 'PS3333')
  565. go
  566. insert sales
  567. values('7131','P3087a', '5/29/87', 25, 'Net 60', 'PS7777')
  568. go
  569. insert sales
  570. values('7067','P2121', '6/15/87', 40, 'Net 30', 'TC3218')
  571. go
  572. insert sales
  573. values('7067','P2121', '6/15/87', 20, 'Net 30', 'TC4203')
  574. go
  575. insert sales
  576. values('7067','P2121', '6/15/87', 20, 'Net 30', 'TC7777')
  577. go
  578. insert titleauthor
  579. values('409-56-7008', 'BU1032', 1, 60)
  580. go
  581. insert titleauthor
  582. values('486-29-1786', 'PS7777', 1, 100)
  583. go
  584. insert titleauthor
  585. values('486-29-1786', 'PC9999', 1, 100)
  586. go
  587. insert titleauthor
  588. values('712-45-1867', 'MC2222', 1, 100)
  589. go
  590. insert titleauthor
  591. values('172-32-1176', 'PS3333', 1, 100)
  592. go
  593. insert titleauthor
  594. values('213-46-8915', 'BU1032', 2, 40)
  595. go
  596. insert titleauthor
  597. values('238-95-7766', 'PC1035', 1, 100)
  598. go
  599. insert titleauthor
  600. values('213-46-8915', 'BU2075', 1, 100)
  601. go
  602. insert titleauthor
  603. values('998-72-3567', 'PS2091', 1, 50)
  604. go
  605. insert titleauthor
  606. values('899-46-2035', 'PS2091', 2, 50)
  607. go
  608. insert titleauthor
  609. values('998-72-3567', 'PS2106', 1, 100)
  610. go
  611. insert titleauthor
  612. values('722-51-5454', 'MC3021', 1, 75)
  613. go
  614. insert titleauthor
  615. values('899-46-2035', 'MC3021', 2, 25)
  616. go
  617. insert titleauthor
  618. values('807-91-6654', 'TC3218', 1, 100)
  619. go
  620. insert titleauthor
  621. values('274-80-9391', 'BU7832', 1, 100)
  622. go
  623. insert titleauthor
  624. values('427-17-2319', 'PC8888', 1, 50)
  625. go
  626. insert titleauthor
  627. values('846-92-7186', 'PC8888', 2, 50)
  628. go
  629. insert titleauthor
  630. values('756-30-7391', 'PS1372', 1, 75)
  631. go
  632. insert titleauthor
  633. values('724-80-9391', 'PS1372', 2, 25)
  634. go
  635. insert titleauthor
  636. values('724-80-9391', 'BU1111', 1, 60)
  637. go
  638. insert titleauthor
  639. values('267-41-2394', 'BU1111', 2, 40)
  640. go
  641. insert titleauthor
  642. values('672-71-3249', 'TC7777', 1, 40)
  643. go
  644. insert titleauthor
  645. values('267-41-2394', 'TC7777', 2, 30)
  646. go
  647. insert titleauthor
  648. values('472-27-2349', 'TC7777', 3, 30)
  649. go
  650. insert titleauthor
  651. values('648-92-1872', 'TC4203', 1, 100)
  652. go
  653. insert titles
  654. values ('PC8888', 'Secrets of Silicon Valley',
  655. 'popular_comp', '1389', $20.00, $8000.00, 10, 4095,
  656. "Muckraking reporting on the world's largest computer hardware and software manufacturers.",
  657. '06/12/85')
  658. go
  659. insert titles
  660. values ('BU1032', "The Busy Executive's Database Guide",
  661. 'business', '1389', $19.99, $5000.00, 10, 4095,
  662. "An overview of available database systems with emphasis on common business applications.  Illustrated.",
  663. '06/12/85')
  664. go
  665. insert titles
  666. values ('PS7777', 'Emotional Security: A New Algorithm',
  667. 'psychology', '0736', $7.99, $4000.00, 10, 3336,
  668. "Protecting yourself and your loved ones from undue emotional stress in the modern world.  Use of computer and nutritional aids emphasized.",
  669. '06/12/85')
  670. go
  671. insert titles
  672. values ('PS3333', 'Prolonged Data Deprivation: Four Case Studies',
  673. 'psychology', '0736', $19.99, $2000.00, 10, 4072,
  674. 'What happens when the data runs dry?  Searching evaluations of information-shortage effects.',
  675. '06/12/85')
  676. go
  677. insert titles
  678. values ('BU1111', 'Cooking with Computers: Surreptitious Balance Sheets',
  679. 'business', '1389', $11.95, $5000.00, 10, 3876,
  680. 'Helpful hints on how to use your electronic resources to the best advantage.', '06/09/85')
  681. go
  682. insert titles
  683. values ('MC2222', 'Silicon Valley Gastronomic Treats',
  684. 'mod_cook', '0877', $19.99, $0.00, 12, 2032,
  685. 'Favorite recipes for quick, easy, and elegant meals.',
  686. '06/09/85')
  687. go
  688. insert titles
  689. values ('TC7777', 'Sushi, Anyone?',
  690. 'trad_cook', '0877', $14.99, $8000.00, 10, 4095,
  691. 'Detailed instructions on how to make authentic Japanese sushi in your spare time.',
  692. '06/12/85')
  693. go
  694. insert titles
  695. values ('TC4203', 'Fifty Years in Buckingham Palace Kitchens',
  696. 'trad_cook', '0877', $11.95, $4000.00, 14, 15096,
  697. "More anecdotes from the Queen's favorite cook describing life among English royalty.  Recipes, techniques, tender vignettes.",
  698. '06/12/85')
  699. go
  700. insert titles
  701. values ('PC1035', 'But Is It User Friendly?',
  702. 'popular_comp', '1389', $22.95, $7000.00, 16, 8780,
  703. "A survey of software for the naive user, focusing on the 'friendliness' of each.",
  704. '06/30/85')
  705. go
  706. insert titles
  707. values('BU2075', 'You Can Combat Computer Stress!',
  708. 'business', '0736', $2.99, $10125.00, 24, 18722,
  709. 'The latest medical and psychological techniques for living with the electronic office.  Easy-to-understand explanations.',
  710. '06/30/85')
  711. go
  712. insert titles
  713. values('PS2091', 'Is Anger the Enemy?',
  714. 'psychology', '0736', $10.95, $2275.00, 12, 2045,
  715. 'Carefully researched study of the effects of strong emotions on the body.  Metabolic charts included.',
  716. '06/15/85')
  717. go
  718. insert titles
  719. values('PS2106', 'Life Without Fear',
  720. 'psychology', '0736', $7.00, $6000.00, 10, 111,
  721. 'New exercise, meditation, and nutritional techniques that can reduce the shock of daily interactions. Popular audience.  Sample menus included, exercise video available separately.',
  722. '10/05/85')
  723. go
  724. insert titles
  725. values('MC3021', 'The Gourmet Microwave',
  726. 'mod_cook', '0877', $2.99, $15000.00, 24, 22246,
  727. 'Traditional French gourmet recipes adapted for modern microwave cooking.',
  728. '06/18/85')
  729. go
  730. insert titles
  731. values('TC3218',
  732. 'Onions, Leeks, and Garlic: Cooking Secrets of the Mediterranean',
  733. 'trad_cook', '0877', $20.95, $7000.00, 10, 375,
  734. 'Profusely illustrated in color, this makes a wonderful gift book for a cuisine-oriented friend.',
  735. '10/21/85')
  736. go
  737. insert titles (title_id, title, pub_id)
  738. values('MC3026', 'The Psychology of Computer Cooking', '0877')
  739. go
  740. insert titles
  741. values ('BU7832', 'Straight Talk About Computers',
  742. 'business', '1389', $19.99, $5000.00, 10, 4095,
  743. 'Annotated analysis of what computers can do for you: a no-hype guide for the critical user.',
  744. '06/22/85')
  745. go
  746. insert titles
  747. values('PS1372',
  748. 'Computer Phobic and Non-Phobic Individuals: Behavior Variations',
  749. 'psychology', '0877', $21.59, $7000.00, 10, 375,
  750. 'A must for the specialist, this book examines the difference between those who hate and fear computers and those who don''t.',
  751. '10/21/85')
  752. go
  753. insert titles (title_id, title, type, pub_id, notes)
  754. values('PC9999', 'Net Etiquette', 'popular_comp', '1389',
  755. 'A must-read for computer conferencing.')
  756. go
  757. insert stores
  758. values('7066',"Barnum's",'567 Pasadena Ave.','Tustin','CA','92789')
  759. go
  760. insert stores
  761. values('7067','News & Brews','577 First St.','Los Gatos','CA','96745')
  762. go
  763. insert stores
  764. values('7131','Doc-U-Mat: Quality Laundry and Books','24-A Avrogado Way','Remulade','WA','98014')
  765. go
  766. insert stores
  767. values('8042','Bookbeat','679 Carson St.','Portland','OR','89076')
  768. go
  769. insert stores
  770. values('6380',"Eric the Read Books",'788 Catamaugus Ave.','Seattle','WA','98056')
  771. go
  772. insert stores
  773. values('7896','Fricative Bookshop','89 Madison St.','Fremont','CA','90019')
  774. go
  775. insert discounts
  776. values('Initial Customer', NULL, NULL, NULL, 10.5)
  777. go
  778. insert discounts
  779. values('Volume Discount', NULL, 100, 1000, 6.7)
  780. go
  781. insert discounts
  782. values('Customer Discount', '8042', NULL, NULL, 5.0)
  783. go
  784. execute sp_primarykey titles, title_id
  785. execute sp_primarykey titleauthor, au_id, title_id
  786. execute sp_primarykey authors, au_id
  787. execute sp_primarykey publishers, pub_id
  788. execute sp_primarykey roysched, title_id
  789. execute sp_primarykey sales, stor_id, title_id, ord_num
  790. execute sp_primarykey stores, stor_id
  791. execute sp_primarykey discounts, discounttype, stor_id     /* problem? */
  792. go
  793. execute sp_foreignkey titleauthor, titles, title_id
  794. execute sp_foreignkey titleauthor, authors, au_id
  795. execute sp_foreignkey roysched, titles, title_id
  796. execute sp_foreignkey sales, titles, title_id
  797. execute sp_foreignkey sales, stores, stor_id
  798. execute sp_foreignkey titles, publishers, pub_id
  799. execute sp_foreignkey discounts, stores, stor_id
  800. go
  801.  
  802. create unique clustered index pubind
  803. on publishers (pub_id)
  804. go
  805. create unique clustered index auidind
  806. on authors (au_id)
  807. go
  808. create nonclustered index aunmind
  809. on authors (au_lname, au_fname)
  810. go
  811. create unique clustered index titleidind
  812. on titles (title_id)
  813. go
  814. create nonclustered index titleind
  815. on titles (title)
  816. go
  817. create unique clustered index taind
  818. on titleauthor (au_id, title_id)
  819. go
  820. create nonclustered index auidind
  821. on titleauthor (au_id)
  822. go
  823. create nonclustered index titleidind
  824. on titleauthor (title_id)
  825. go
  826. create nonclustered index titleidind
  827. on sales (title_id)
  828. go
  829. create nonclustered index titleidind
  830. on roysched (title_id)
  831. go
  832. create rule pub_idrule
  833. as @pub_id in ("1389", "0736", "0877", "1622", "1756")
  834. or @pub_id like "99[0-9][0-9]"
  835. go
  836. sp_bindrule pub_idrule, "publishers.pub_id"
  837. go
  838. create rule ziprule
  839. as @zip like "[0-9][0-9][0-9][0-9][0-9]"
  840. go
  841. sp_bindrule ziprule, "authors.zip"
  842. go
  843. create trigger deltitle
  844. on titles
  845. for delete
  846. as
  847. if (select count(*) from deleted, sales
  848. where sales.title_id = deleted.title_id) >0
  849. begin
  850.     rollback transaction
  851.     print "You can't delete a title with sales."
  852. end
  853. go
  854. create view titleview
  855. as
  856. select title, au_ord, au_lname,
  857. price, ytd_sales, pub_id
  858. from authors, titles, titleauthor
  859. where authors.au_id = titleauthor.au_id
  860. and titles.title_id = titleauthor.title_id
  861. go
  862. create procedure byroyalty @percentage int
  863. as
  864. select au_id from titleauthor
  865. where titleauthor.royaltyper = @percentage
  866. go
  867. grant execute on byroyalty to public
  868. go
  869. create procedure reptq1 as
  870. select pub_id, title_id, price, pubdate
  871. from titles
  872. where price is not null
  873. order by pub_id
  874. compute avg(price) by pub_id
  875. compute avg(price)
  876. go
  877. grant execute on reptq1 to public
  878. go
  879. create procedure reptq2 as
  880. select type, pub_id, titles.title_id, au_ord,
  881.  Name = substring (au_lname, 1,15),
  882.  ytd_sales
  883. from titles, authors, titleauthor
  884. where titles.title_id = titleauthor.title_id
  885. and authors.au_id = titleauthor.au_id
  886. and pub_id is not null
  887. order by pub_id, type
  888. compute avg(ytd_sales) by pub_id, type
  889. compute avg(ytd_sales) by pub_id
  890. go
  891. grant execute on reptq2 to public
  892. go
  893. create procedure reptq3 @lolimit money, @hilimit money,
  894. @type char(12)
  895. as
  896. select pub_id, type, title_id, price
  897. from titles
  898. where price >@lolimit and price <@hilimit
  899.  and type = @type or type like "%cook%"
  900. order by pub_id, type
  901. compute count(title_id) by pub_id, type
  902. go
  903. grant execute on reptq3 to public
  904. go
  905. grant create procedure to public
  906. go
  907. if exists (select * from master.dbo.sysdatabases
  908.         where name = "pubs")
  909. begin
  910.     execute sp_adduser guest
  911. end
  912. go
  913. if exists (select * from master.dbo.sysdatabases
  914.         where name = "pubs")
  915. begin
  916.     grant all on publishers to guest
  917.     grant all on titles to guest
  918.     grant all on authors to guest
  919.     grant all on titleauthor to guest
  920.     grant all on sales to guest
  921.     grant all on roysched to guest
  922.     grant all on stores to guest
  923.     grant all on discounts to guest
  924.     grant exec on byroyalty to guest
  925.     grant create table to guest
  926.     grant create view to guest
  927.     grant create rule to guest
  928.     grant create default to guest
  929.     grant create procedure to guest
  930. end
  931. go
  932. checkpoint
  933. go
  934. use master
  935. go
  936. grant exec on sp_bindefault to guest
  937. grant exec on sp_unbindefault to guest
  938. grant exec on sp_bindrule to guest
  939. grant exec on sp_unbindrule to guest
  940. grant exec on sp_addtype to guest
  941. grant exec on sp_droptype to guest
  942. grant exec on sp_spaceused to guest
  943. grant exec on sp_help to guest
  944. grant exec on sp_helpgroup to guest
  945. grant exec on sp_helpindex to guest
  946. grant exec on sp_helprotect to guest
  947. go
  948. checkpoint
  949. go
  950.