Advertisement
jamieyello

Crap

Apr 10th, 2017
660
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.00 KB | None | 0 0
  1. -- --------------------------------------------------------------------------------
  2. -- Name: Jamie Cappel
  3. -- Class: IT-111-001
  4. -- Abstract: Golfathon
  5. -- --------------------------------------------------------------------------------
  6.  
  7. -- --------------------------------------------------------------------------------
  8. -- Options
  9. -- --------------------------------------------------------------------------------
  10. USE joe; -- Get out of the master database
  11. SET NOCOUNT ON; -- Report only errors
  12.  
  13. -- --------------------------------------------------------------------------------
  14. -- Drop Tables
  15. -- --------------------------------------------------------------------------------
  16.  
  17. --Dependant Tables in Cascading Dependancy
  18. DROP TABLE TEventCorporateSponsers
  19. DROP TABLE TEventSponsers
  20. DROP TABLE TEventTeams
  21. DROP TABLE TEvents
  22.  
  23. DROP TABLE TSponserships
  24. DROP TABLE TSponsers
  25. DROP TABLE TCorporateSponserships
  26. DROP TABLE TCorporateSponsers
  27.  
  28. DROP TABLE TTeamPlayers
  29. DROP TABLE TPlayers
  30. DROP TABLE TTeams
  31.  
  32. --Basic Tables
  33. DROP TABLE TStates
  34. DROP TABLE TShirtSizes
  35. DROP TABLE TGenders
  36. DROP TABLE TTypesOfTeams
  37. DROP TABLE TLevelsOfTeams
  38. DROP TABLE TPayStatuses
  39. DROP TABLE TPayTypes
  40. DROP TABLE TAffiliations
  41.  
  42. -- --------------------------------------------------------------------------------
  43. -- Create Tables
  44. -- --------------------------------------------------------------------------------
  45. CREATE TABLE TPlayers
  46. (
  47. intPlayerID INTEGER NOT NULL
  48. ,strFirstName VARCHAR(50) NOT NULL
  49. ,strLastName VARCHAR(50) NOT NULL
  50. ,strAddress VARCHAR(50) NOT NULL
  51. ,intStateID INTEGER NOT NULL
  52. ,strCity VARCHAR(50) NOT NULL
  53. ,strZip VARCHAR(50) NOT NULL
  54. ,strPhoneNumber VARCHAR(50) NOT NULL
  55. ,strEmail VARCHAR(50) NOT NULL
  56. ,intShirtSizeID INTEGER NOT NULL
  57. ,CONSTRAINT TPlayers_PK PRIMARY KEY (intPlayerID)
  58. )
  59.  
  60. CREATE TABLE TEvents
  61. (
  62. intEventID INTEGER NOT NULL
  63. ,dtmDate DATETIME NOT NULL
  64. ,CONSTRAINT TEvents_PK PRIMARY KEY (intEventID)
  65. )
  66.  
  67. CREATE TABLE TEventTeams
  68. (
  69. intEventID INTEGER NOT NULL
  70. ,intTeamID INTEGER NOT NULL
  71. ,strReasonForJoining VARCHAR(50) NOT NULL
  72. ,CONSTRAINT TEventTeams_PK PRIMARY KEY (intEventID)
  73. )
  74.  
  75. CREATE TABLE TEventSponsers
  76. (
  77. intEventID INTEGER NOT NULL
  78. ,intSponserID INTEGER NOT NULL
  79. ,intAffiliationID INTEGER NOT NULL
  80. ,monAmount MONEY NOT NULL
  81. ,CONSTRAINT TEventSponsers_PK PRIMARY KEY (intEventID)
  82. )
  83.  
  84. CREATE TABLE TEventCorporateSponsers
  85. (
  86. intEventID INTEGER NOT NULL
  87. ,intSponserID INTEGER NOT NULL
  88. ,monAmount MONEY NOT NULL
  89. ,CONSTRAINT TEventCorporateSponsers_PK PRIMARY KEY (intEventID)
  90. )
  91.  
  92. CREATE TABLE TStates -- Data
  93. (
  94. intStateID INTEGER NOT NULL
  95. ,strName VARCHAR(50) NOT NULL
  96. ,CONSTRAINT TStates_PK PRIMARY KEY (intStateID)
  97. )
  98.  
  99. CREATE TABLE TShirtSizes -- Data
  100. (
  101. intShirtSizeID INTEGER NOT NULL
  102. ,strShirtSizeDesc VARCHAR(50) NOT NULL
  103. ,CONSTRAINT TShirtSizes_PK PRIMARY KEY (intShirtSizeID)
  104. )
  105.  
  106. CREATE TABLE TSponsers
  107. (
  108. intSponserID INTEGER NOT NULL
  109. ,strFirstName VARCHAR(50) NOT NULL
  110. ,strLastName VARCHAR(50) NOT NULL
  111. ,strCity VARCHAR(50) NOT NULL
  112. ,intStateID INTEGER NOT NULL
  113. ,intZip INTEGER NOT NULL
  114. ,strPhoneNumber VARCHAR(50) NOT NULL
  115. ,strEmail VARCHAR(50) NOT NULL
  116. ,CONSTRAINT TSponsers_PK PRIMARY KEY (intSponserID)
  117. )
  118.  
  119. CREATE TABLE TAffiliations -- Data
  120. (
  121. intAffiliationID INTEGER NOT NULL
  122. ,strDesc VARCHAR(50) NOT NULL
  123. ,CONSTRAINT TAffiliations_PK PRIMARY KEY (intAffiliationID)
  124. )
  125.  
  126. CREATE TABLE TSponserships
  127. (
  128. intSponserID INTEGER NOT NULL
  129. ,intSponsershipIndex INTEGER NOT NULL
  130. ,intStatusID INTEGER NOT NULL
  131. ,intTypeID INTEGER NOT NULL
  132. ,monAmount MONEY NOT NULL
  133. ,dtmDate DATETIME NOT NULL
  134. ,CONSTRAINT TSponserships_PK PRIMARY KEY (intSponserID, intSponsershipIndex)
  135. )
  136.  
  137. CREATE TABLE TCorporateSponsers
  138. (
  139. intSponserID INTEGER NOT NULL
  140. ,strName VARCHAR(50) NOT NULL
  141. ,strCity VARCHAR(50) NOT NULL
  142. ,intStateID INTEGER NOT NULL
  143. ,intZip INTEGER NOT NULL
  144. ,strPhoneNumber VARCHAR(50) NOT NULL
  145. ,strEmail VARCHAR(50) NOT NULL
  146. ,CONSTRAINT TCorporateSponsers_PK PRIMARY KEY (intSponserID)
  147. )
  148.  
  149. CREATE TABLE TCorporateSponserships
  150. (
  151. intSponserID INTEGER NOT NULL
  152. ,intSponsershipIndex INTEGER NOT NULL
  153. ,intStatusID INTEGER NOT NULL
  154. ,intTypeID INTEGER NOT NULL
  155. ,monAmount MONEY NOT NULL
  156. ,dtmDate DATETIME NOT NULL
  157. ,CONSTRAINT TCorporateSponserships_PK PRIMARY KEY (intSponserID, intSponsershipIndex)
  158. )
  159.  
  160.  
  161. CREATE TABLE TPayStatuses -- Data
  162. (
  163. intStatusID INTEGER NOT NULL
  164. ,strStatus VARCHAR(50) NOT NULL
  165. ,CONSTRAINT TPayStatuses_PK PRIMARY KEY (intStatusID)
  166. )
  167.  
  168. CREATE TABLE TPayTypes -- Data
  169. (
  170. intTypeID INTEGER NOT NULL
  171. ,strName VARCHAR(50) NOT NULL
  172. ,CONSTRAINT TPayTypes_PK PRIMARY KEY (intTypeID)
  173. )
  174.  
  175. CREATE TABLE TTeams
  176. (
  177. intTeamID INTEGER NOT NULL
  178. ,strName VARCHAR(50) NOT NULL
  179. ,intTypeID INTEGER NOT NULL
  180. ,intLevelID INTEGER NOT NULL
  181. ,intGenderID INTEGER NOT NULL
  182. ,CONSTRAINT TTeams_PK PRIMARY KEY (intTeamID)
  183. )
  184.  
  185. CREATE TABLE TTeamPlayers
  186. (
  187. intTeamID INTEGER NOT NULL
  188. ,intPlayerID INTEGER NOT NULL
  189. ,CONSTRAINT TTeamPlayers_PK PRIMARY KEY (intTeamID, intPlayerID)
  190. )
  191.  
  192. CREATE TABLE TGenders -- Data
  193. (
  194. intGenderID INTEGER NOT NULL
  195. ,strName VARCHAR(50) NOT NULL
  196. ,CONSTRAINT TGenders_PK PRIMARY KEY (intGenderID)
  197. )
  198.  
  199. CREATE TABLE TTypesOfTeams -- Data
  200. (
  201. intTypeID INTEGER NOT NULL
  202. ,strName VARCHAR(50) NOT NULL
  203. ,CONSTRAINT TTypesOfTeams_PK PRIMARY KEY (intTypeID)
  204. )
  205.  
  206. CREATE TABLE TLevelsOfTeams -- Data
  207. (
  208. intLevelID INTEGER NOT NULL
  209. ,strName VARCHAR(50) NOT NULL
  210. ,CONSTRAINT TLevelsOfTeams_PK PRIMARY KEY (intLevelID)
  211. )
  212.  
  213. -- --------------------------------------------------------------------------------
  214. -- 1) Identify and Create Foreign Keys
  215. -- --------------------------------------------------------------------------------
  216. -- ALTER TABLE <child table name> ADD CONSTRAINT <constraint name>
  217. -- FOREIGN KEY ( <child column(s)> ) REFERENCES <parent table name> ( <parent table column(s)> )
  218. --
  219. -- # Child Parent Column(s)
  220. -- - ----- ------ ---------
  221. -- 1 TPlayers TStates intStateID
  222. -- 2 TPlayers TShirtSizes intShirtSizeID
  223. -- 3 TSponsers TStates intStateID
  224. -- 4 TSponserships TSponsers intSponserID
  225.  
  226. -- 5 TSponserships TPayTypes intTypeID
  227. -- 6 TSponserships TPayStatuses intStatusID
  228. -- 7 TCorporateSponserships TCorporateSponsers intSponserID
  229. -- 8 TCorporateSponserships TPayTypes intTypeID
  230.  
  231. -- 9 TCorporateSponserships TPayStatuses intStatusID
  232. -- 10 TTeams TGenders intGenderID
  233. -- 11 TTeams TLevelsOfTeams intLevelID
  234. -- 12 TTeams TTypesOfTeams intTypeID
  235.  
  236. -- 14 TTeamPlayers TPlayers intPlayerID
  237. -- 15 TTeamPlayers TTeams intTeamID
  238. -- 16
  239.  
  240. -- 17 TEventTeams TEvents intEventID
  241. -- 18 TEventSponsers TEvents intEventID
  242. -- 19 TEventTeams TTeams intTeamID
  243. -- 20 TEventSponsers TSponsers intSponserID
  244.  
  245. -- 21 TEventCorporateSponsers TCorporateSponsers intSponserID
  246. -- 22 TEventCorporateSponsers TEvents intEventID
  247.  
  248. -- 1
  249. ALTER TABLE TPlayers ADD CONSTRAINT TPlayers_TStates_FK
  250. FOREIGN KEY ( intStateID ) REFERENCES TStates ( intStateID )
  251.  
  252. -- 2
  253. ALTER TABLE TPlayers ADD CONSTRAINT TPlayers_TShirtSizes_FK
  254. FOREIGN KEY ( intShirtSizeID ) REFERENCES TShirtSizes ( intShirtSizeID )
  255.  
  256. -- 3
  257. ALTER TABLE TSponsers ADD CONSTRAINT TSponsers_TStates_FK
  258. FOREIGN KEY ( intStateID ) REFERENCES TStates ( intStateID )
  259.  
  260. -- 4
  261. ALTER TABLE TSponserships ADD CONSTRAINT TSponserships_TSponsers_FK
  262. FOREIGN KEY ( intSponserID ) REFERENCES TSponsers ( intSponserID )
  263.  
  264.  
  265. -- 5
  266. ALTER TABLE TSponserships ADD CONSTRAINT TSponserships_TPayTypes_FK
  267. FOREIGN KEY ( intTypeID ) REFERENCES TPayTypes ( intTypeID )
  268.  
  269. -- 6
  270. ALTER TABLE TSponserships ADD CONSTRAINT TSponserships_TPayStatuses_FK
  271. FOREIGN KEY ( intStatusID ) REFERENCES TPayStatuses ( intStatusID )
  272.  
  273. -- 7
  274. ALTER TABLE TCorporateSponserships ADD CONSTRAINT TCorporateSponserships_TCorporateSponsers_FK
  275. FOREIGN KEY ( intSponserID) REFERENCES TCorporateSponsers ( intSponserID )
  276.  
  277. -- 8
  278. ALTER TABLE TCorporateSponserships ADD CONSTRAINT TCorporateSponserships_TPayTypes_FK
  279. FOREIGN KEY ( intTypeID ) REFERENCES TPayTypes ( intTypeID )
  280.  
  281.  
  282. -- 9
  283. ALTER TABLE TCorporateSponserships ADD CONSTRAINT TCorporateSponserships_TPayStatuses_FK
  284. FOREIGN KEY ( intStatusID ) REFERENCES TPayStatuses ( intStatusID )
  285.  
  286. -- 10
  287. ALTER TABLE TTeams ADD CONSTRAINT TTeams_TGenders_FK
  288. FOREIGN KEY ( intGenderID ) REFERENCES TGenders ( intGenderID )
  289.  
  290. -- 11
  291. ALTER TABLE TTeams ADD CONSTRAINT TTeams_TLevelsOfTeams_FK
  292. FOREIGN KEY ( intLevelID ) REFERENCES TLevelsOfTeams ( intLevelID )
  293.  
  294. -- 12
  295. ALTER TABLE TTeams ADD CONSTRAINT TTeams_TTypesOfTeams_FK
  296. FOREIGN KEY ( intTypeID ) REFERENCES TTypesOfTeams ( intTypeID )
  297.  
  298.  
  299. -- 13
  300.  
  301.  
  302. -- 14
  303. ALTER TABLE TTeamPlayers ADD CONSTRAINT TTeamPlayers_TPlayers_FK
  304. FOREIGN KEY ( intPlayerID ) REFERENCES TPlayers ( intPlayerID )
  305.  
  306. -- 15
  307. ALTER TABLE TTeamPlayers ADD CONSTRAINT TTeamPlayers_TTeams_FK
  308. FOREIGN KEY ( intTeamID ) REFERENCES TTeams ( intTeamID )
  309.  
  310. -- 16
  311.  
  312.  
  313.  
  314. -- 17
  315. ALTER TABLE TEventTeams ADD CONSTRAINT TEventTeams_TEvents_FK
  316. FOREIGN KEY ( intEventID ) REFERENCES TEvents ( intEventID )
  317.  
  318. -- 18
  319. ALTER TABLE TEventSponsers ADD CONSTRAINT TEventSponsers_TEvents_FK
  320. FOREIGN KEY ( intEventID ) REFERENCES TEvents ( intEventID )
  321.  
  322. -- 19
  323. ALTER TABLE TEventTeams ADD CONSTRAINT TEventTeams_TTeams_FK
  324. FOREIGN KEY ( intTeamID ) REFERENCES TTeams ( intTeamID )
  325.  
  326. -- 20
  327. ALTER TABLE TEventSponsers ADD CONSTRAINT TEventSponsers_TSponsers_FK
  328. FOREIGN KEY ( intSponserID ) REFERENCES TSponsers ( intSponserID )
  329.  
  330.  
  331. -- 21
  332. ALTER TABLE TEventCorporateSponsers ADD CONSTRAINT TEventCorporateSponsers_TCorporateSponsers_FK
  333. FOREIGN KEY ( intSponserID ) REFERENCES TCorporateSponsers ( intSponserID )
  334.  
  335. -- 22
  336. ALTER TABLE TEventCorporateSponsers ADD CONSTRAINT TEventCorporateSponsers_TEvents_FK
  337. FOREIGN KEY ( intEventID ) REFERENCES TEvents ( intEventID )
  338.  
  339. -- 23
  340. ALTER TABLE TEventSponsers ADD CONSTRAINT TEventSponsers_TAffiliations_FK
  341. FOREIGN KEY ( intAffiliationID ) REFERENCES TAffiliations ( intAffiliationID )
  342.  
  343. -- --------------------------------------------------------------------------------
  344. -- 2) Create Data
  345. -- --------------------------------------------------------------------------------
  346.  
  347. -- Basic Data ---------------------------------------------------------------------
  348. INSERT INTO TShirtSizes ( intShirtSizeID, strShirtSizeDesc )
  349. VALUES ( 1, 'Mens Small' )
  350. ,( 2, 'Mens Medium' )
  351. ,( 3, 'Mens Large' )
  352. ,( 4, 'Mens XLarge' )
  353. ,( 5, 'Womens Small' )
  354. ,( 6, 'Womens Medium' )
  355. ,( 7, 'Womens Large' )
  356. ,( 8, 'Womens XLarge' )
  357.  
  358. INSERT INTO TStates ( intStateID, strName )
  359. VALUES ( 1, 'Ohio' )
  360. ,( 2, 'Kentucky' )
  361. ,( 3, 'Indiana' )
  362.  
  363. INSERT INTO TGenders ( intGenderID, strName )
  364. VALUES ( 1, 'Male' )
  365. ,( 2, 'Female' )
  366.  
  367. INSERT INTO TLevelsOfTeams ( intLevelID, strName )
  368. VALUES ( 1, 'Freshman' )
  369. ,( 2, 'Junior Varsity' )
  370. ,( 3, 'Varsity' )
  371.  
  372. INSERT INTO TTypesOfTeams ( intTypeID, strName )
  373. VALUES ( 1, 'Basketball' )
  374. ,( 2, 'Baseball' )
  375. ,( 3, 'Football' )
  376. ,( 4, 'Volleyball' )
  377. ,( 5, 'Soccer' )
  378. ,( 6, 'Cross Country' )
  379. ,( 7, 'Track' )
  380. ,( 8, 'Softball' )
  381. ,( 9, 'Golf' )
  382. ,( 10, 'Swimming' )
  383.  
  384. INSERT INTO TPayStatuses ( intStatusID, strStatus)
  385. VALUES ( 1, 'Unpaid' )
  386. ,( 2, 'Paid' )
  387.  
  388. INSERT INTO TPayTypes ( intTypeID, strName )
  389. VALUES ( 1, 'Check' )
  390. ,( 2, 'Cash' )
  391. ,( 3, 'Credit Card' )
  392.  
  393. INSERT INTO TAffiliations ( intAffiliationID, strDesc )
  394. VALUES ( 1, 'Friend')
  395. , ( 2, 'Parent')
  396. , ( 3, 'Coach')
  397.  
  398. --Dependant Data-------------------------------------------------------------------
  399.  
  400. --Teams and Player Data
  401. INSERT INTO TTeams(intTeamID, strName, intTypeID, intLevelID, intGenderID)
  402. VALUES (1, 'The B-Ball Players', 1, 1, 1)
  403. ,(2, 'The Golfers', 9, 2, 2)
  404.  
  405. INSERT INTO TPlayers(intPlayerID, strFirstName, strLastName, strAddress, strCity, intStateID, strZip, strPhoneNumber, strEmail, intShirtSizeID)
  406. VALUES ( 1, 'Bob', 'Nields', '8741 Rosebrook Drive', 'Florence', 2, '41042', '8597602063', 'bnields@gmail.com', 4)
  407. ,( 2, 'Jay', 'Graue', '1111 SHDHS Drive', 'Florence', 2, '41042', '8597602222', 'jgraue@gmail.com', 4)
  408. ,( 3, 'Mary', 'Beimesch', '4444 Tobertge Drive', 'Hebron', 2, '41012', '8597603333', 'mb@gmail.com', 4)
  409. ,( 4, 'Tony', 'Hardan', '2222 Track', 'Ft. Thomas', 2, '41018', '8592222063', 'thardon@gmail.com', 4)
  410. ,( 5, 'Iwana', 'Bucks', '2222 Track', 'Ft. Thomas', 2, '41018', '8592222063', 'thardon@gmail.com', 4)
  411. ,( 6, 'Jef', 'Hardan', '2222 Track', 'Ft. Thomas', 2, '41018', '8592222063', 'thardon@gmail.com', 4)
  412. ,( 7, 'Kevin', 'Bucks', '2222 Track', 'Ft. Thomas', 2, '41018', '8592222063', 'thardon@gmail.com', 4)
  413.  
  414. INSERT INTO TTeamPlayers(intTeamID, intPlayerID)
  415. VALUES (2, 1)
  416. ,(2, 2)
  417. ,(2, 3)
  418. ,(2, 4)
  419. ,(2, 5)
  420. ,(1, 6)
  421. ,(1, 7)
  422.  
  423. --Events and Sponserships Data
  424. INSERT INTO TSponsers (intSponserID, strFirstName, strLastName, strCity, intStateID, intZip, strPhoneNumber, strEmail)
  425. VALUES (1, 'Joe', 'Sponserman', 'Cincinnati', 1,'23232', '555 555 5554', 'yy@ioio.com')
  426. ,(2, 'Boen', 'Sponserman', 'Cincinnati', 1, '23232', '555 555 5554', 'yy@ioio.com')
  427. ,(3, 'Blub', 'Sponserman', 'Cincinnati', 1, '23232', '555 555 5554', 'yy@ioio.com')
  428. ,(4, 'Sub', 'Sponserman', 'Cincinnati', 1, '23232', '555 555 5554', 'yy@ioio.com')
  429. ,(5, 'Kevin', 'Sponserman', 'Cincinnati', 1, '23232', '555 555 5554', 'yy@ioio.com')
  430. ,(6, 'Jake', 'Sponserman', 'Cincinnati', 1, '23232', '555 555 5554', 'yy@ioio.com')
  431. ,(7, 'Jacob', 'Sponserman', 'Cincinnati', 1, '23232', '555 555 5554', 'yy@ioio.com')
  432. ,(8, 'Blart', 'Sponserman', 'Cincinnati', 1, '23232', '555 555 5554', 'yy@ioio.com')
  433. ,(9, 'Bob', 'Sponserman', 'Cincinnati', 1, '23232', '555 555 5554', 'yy@ioio.com')
  434. ,(10, 'Blartman', 'Sponserman', 'Cincinnati',1, '23232', '555 555 5554', 'yy@ioio.com')
  435. ,(11, 'Joseph', 'Sponserman', 'Cincinnati', 1, '23232', '555 555 5554', 'yy@ioio.com')
  436. ,(12, 'Maria', 'Sponserman', 'Cincinnati', 1, '23232', '555 555 5554', 'yy@ioio.com')
  437.  
  438. INSERT INTO TCorporateSponsers(intSponserID, strName, strCity, intStateID, intZip, strPhoneNumber, strEmail)
  439. VALUES (1, 'Spiderman', 'Cincinnati', 1, '23232', '555 555 5554', 'yy@ioio.com')
  440. ,(2, 'Superman', 'Cincinnati', 1, '23232', '555 555 5554', 'yy@ioio.com')
  441. ,(3, 'Batman', 'Cincinnati', 1, '23232', '555 555 5554', 'yy@ioio.com')
  442. ,(4, 'Wonder Woman', 'Cincinnati', 1, '23232', '555 555 5554', 'yy@ioio.com')
  443. ,(5, 'The one Alien guy from the Justice League', 'Cincinnati', 1, '23232', '555 555 5554', 'yy@ioio.com')
  444.  
  445. INSERT INTO TEvents ( intEventID, dtmDate )
  446. VALUES (1, '2015')
  447. ,(2, '2016')
  448.  
  449. --INSERT INTO TEventTeams( intEventID, intTeamID, strReasonForJoining )
  450. --VALUES (1, )
  451.  
  452. --INSERT INTO TEventSponsers(intEventID, intSponserID, intAffiliationID, monAmount)
  453. --VALUES ()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement