Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 1st, 2012  |  syntax: None  |  size: 24.57 KB  |  hits: 6  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Getting ERROR 1701, ERROR 1452 and ERROR 1305 errors in MySQL - Need some expertise
  2. -- This sql script creates the structure.
  3. -- of the rugby club database.
  4.  
  5. DROP DATABASE IF EXISTS database_rugby;
  6.  
  7. CREATE DATABASE database_rugby;
  8.  
  9. USE database_rugby;
  10.  
  11. -- Create the "coach" table.
  12. DROP TABLE IF EXISTS `database_rugby`.`coach` ;
  13. CREATE  TABLE IF NOT EXISTS `database_rugby`.`coach` (
  14.   `coachID` INT(5) NOT NULL ,
  15.   `dateBeganCoaching` DATE NOT NULL ,
  16.   `personID` INT(5) NOT NULL ,
  17.   PRIMARY KEY (`coachID`))
  18. ENGINE = InnoDB;
  19.  
  20.  
  21. -- Create the "grade" table.
  22. DROP TABLE IF EXISTS `database_rugby`.`grade` ;
  23. CREATE  TABLE IF NOT EXISTS `database_rugby`.`grade` (
  24.   `gradeID` INT(5) NOT NULL AUTO_INCREMENT ,
  25.   `gradeName` VARCHAR(50) NOT NULL ,
  26.   `minWeight` INT(3) NOT NULL ,
  27.   `maxWeight` INT(3) NOT NULL ,
  28.   `minAge` INT(3) NOT NULL ,
  29.   `maxAge` INT(3) NOT NULL ,
  30.   `ballSize` INT(1) NOT NULL ,
  31.   PRIMARY KEY (`gradeID`) )
  32. ENGINE = InnoDB;
  33.  
  34.  
  35. -- Create the "coachQualification" table.
  36. DROP TABLE IF EXISTS `database_rugby`.`coachQualification` ;
  37.  
  38. CREATE  TABLE IF NOT EXISTS `database_rugby`.`coachQualification` (
  39.   `qualID` INT(5) NOT NULL AUTO_INCREMENT ,
  40.   `qualName` CHAR(5) NOT NULL ,
  41.   `gradeID` INT(5) NOT NULL ,
  42.   PRIMARY KEY (`qualID`) ,
  43.   INDEX `gradeID` (`gradeID` ASC) ,
  44.   CONSTRAINT `coachQualification_ibfk_1`
  45.     FOREIGN KEY (`gradeID`)
  46.     REFERENCES `database_rugby`.`grade` (`gradeID`)
  47.     ON DELETE CASCADE
  48.     ON UPDATE CASCADE)
  49. ENGINE = InnoDB;
  50.  
  51.  
  52. -- Create the "parent" table.
  53. DROP TABLE IF EXISTS `database_rugby`.`parent` ;
  54. CREATE  TABLE IF NOT EXISTS `database_rugby`.`parent` (
  55.   `parentID` INT(5) NOT NULL ,
  56.   `personID` INT(5) NOT NULL ,
  57.   PRIMARY KEY (`parentID`))
  58. ENGINE = InnoDB;
  59.  
  60.  
  61. -- Create the "school" table.
  62. DROP TABLE IF EXISTS `database_rugby`.`school` ;
  63. CREATE  TABLE IF NOT EXISTS `database_rugby`.`school` (
  64.   `schoolID` INT(5) NOT NULL AUTO_INCREMENT ,
  65.   `schoolName` VARCHAR(100) NOT NULL ,
  66.   PRIMARY KEY (`schoolID`))
  67. ENGINE = InnoDB;
  68.  
  69.  
  70. -- Create the "player" table.
  71. --
  72. -- Inherits fields from the "person"
  73. -- and "school" tables.
  74. DROP TABLE IF EXISTS `database_rugby`.`player` ;
  75.  
  76. CREATE  TABLE IF NOT EXISTS `database_rugby`.`player` (
  77.   `playerID` INT(5) NOT NULL ,
  78.   `personID` INT(5) NOT NULL ,
  79.   `schoolID` INT(5) NOT NULL ,
  80.   PRIMARY KEY (`playerID`) ,
  81.   INDEX `schoolID` (`schoolID` ASC) ,
  82.   CONSTRAINT `player_ibfk_1`
  83.     FOREIGN KEY (`schoolID`)
  84.     REFERENCES `database_rugby`.`school` (`schoolID` )
  85.     ON DELETE CASCADE
  86.     ON UPDATE CASCADE)
  87. ENGINE = InnoDB;
  88.  
  89.  
  90. -- Create the "person" table.
  91. --
  92. -- This table has one:one relationships
  93. -- with the parent, coach and player
  94. -- tables.
  95. DROP TABLE IF EXISTS `database_rugby`.`person` ;
  96. CREATE  TABLE IF NOT EXISTS `database_rugby`.`person` (
  97.   `personID` INT(5) NOT NULL AUTO_INCREMENT ,
  98.   `firstName` VARCHAR(50) NOT NULL ,
  99.   `lastName` VARCHAR(50) NOT NULL ,
  100.   `dateOfBirth` DATE NOT NULL ,
  101.   `streetAddress` VARCHAR(150) NOT NULL ,
  102.   `suburbAddress` VARCHAR(150) NULL DEFAULT NULL ,
  103.   `cityAddress` VARCHAR(150) NOT NULL ,
  104.   `photo` BLOB NULL DEFAULT NULL ,
  105.   `parent_parentID` INT(5) NOT NULL DEFAULT '0' ,
  106.   `coach_coachID` INT(5) NOT NULL DEFAULT '0' ,
  107.   `player_playerID` INT(5) NOT NULL DEFAULT '0' ,
  108.   `parent_parentID1` INT(5) NOT NULL DEFAULT '0' ,
  109.   `player_playerID1` INT(5) NOT NULL DEFAULT '0' ,
  110.   `coach_coachID1` INT(5) NOT NULL DEFAULT '0' ,
  111.   `coach_coachID2` INT(5) NOT NULL DEFAULT '0' ,
  112.   `parent_parentID2` INT(5) NOT NULL DEFAULT '0' ,
  113.   `player_playerID2` INT(5) NOT NULL DEFAULT '0' ,
  114.   PRIMARY KEY (`personID`) ,
  115.   INDEX `fk_person_coach1` (`coach_coachID2` ASC) ,
  116.   INDEX `fk_person_parent1` (`parent_parentID2` ASC) ,
  117.   INDEX `fk_person_player1` (`player_playerID2` ASC) ,
  118.   CONSTRAINT `fk_person_coach1`
  119.     FOREIGN KEY (`coach_coachID2` )
  120.     REFERENCES `database_rugby`.`coach` (`coachID`)
  121.     ON DELETE NO ACTION
  122.     ON UPDATE NO ACTION,
  123.   CONSTRAINT `fk_person_parent1`
  124.     FOREIGN KEY (`parent_parentID2`)
  125.     REFERENCES `database_rugby`.`parent` (`parentID`)
  126.     ON DELETE NO ACTION
  127.     ON UPDATE NO ACTION,
  128.   CONSTRAINT `fk_person_player1`
  129.     FOREIGN KEY (`player_playerID2`)
  130.     REFERENCES `database_rugby`.`player` (`playerID`)
  131.     ON DELETE NO ACTION
  132.     ON UPDATE NO ACTION)
  133. ENGINE = InnoDB;
  134.  
  135.  
  136. -- Create the "homePhone" table.
  137. DROP TABLE IF EXISTS `database_rugby`.`homePhone` ;
  138. CREATE  TABLE IF NOT EXISTS `database_rugby`.`homePhone` (
  139.   `homePhoneID` INT(5) NOT NULL AUTO_INCREMENT ,
  140.   `homeNumber` CHAR(9) NOT NULL ,
  141.   PRIMARY KEY (`homePhoneID`))
  142. ENGINE = InnoDB;
  143.  
  144.  
  145. -- Create the "mobilePhone" table.
  146. DROP TABLE IF EXISTS `database_rugby`.`mobilePhone` ;
  147.  
  148. CREATE  TABLE IF NOT EXISTS `database_rugby`.`mobilePhone` (
  149.   `mobilePhoneID` INT(5) NOT NULL AUTO_INCREMENT ,
  150.   `mobileNumber` CHAR(10) NULL DEFAULT NULL ,
  151.   PRIMARY KEY (`mobilePhoneID`))
  152. ENGINE = InnoDB;
  153.  
  154.  
  155. -- Create the "emailAddress" table.
  156. DROP TABLE IF EXISTS `database_rugby`.`emailAddress` ;
  157.  
  158. CREATE  TABLE IF NOT EXISTS `database_rugby`.`emailAddress` (
  159.   `emailAddressID` INT(5) NOT NULL AUTO_INCREMENT ,
  160.   `emailAddress` CHAR(10) NULL DEFAULT NULL ,
  161.   PRIMARY KEY (`emailAddressID`))
  162. ENGINE = InnoDB;
  163.  
  164.  
  165. -- Create the "Contact" table
  166. --
  167. -- This is a linking table
  168. -- that describes the many:many
  169. -- relationships between "person"
  170. -- and the "homePhone", "mobilePhone",
  171. -- and "emailAddress" tables.
  172. DROP TABLE IF EXISTS `database_rugby`.`contact` ;
  173. CREATE  TABLE IF NOT EXISTS `database_rugby`.`contact` (
  174.   `personID` INT(5) NOT NULL ,
  175.   `homePhoneID` INT(5) NOT NULL ,
  176.   `mobilePhoneID` INT(5) NULL DEFAULT NULL ,
  177.   `emailAddressID` INT(5) NULL DEFAULT NULL ,
  178.   INDEX `personID` (`personID` ASC) ,
  179.   INDEX `homePhoneID` (`homePhoneID` ASC) ,
  180.   INDEX `mobilePhoneID` (`mobilePhoneID` ASC) ,
  181.   INDEX `emailAddressID` (`emailAddressID` ASC) ,
  182.   CONSTRAINT `contact_ibfk_1`
  183.     FOREIGN KEY (`personID` )
  184.     REFERENCES `database_rugby`.`person` (`personID`)
  185.     ON DELETE CASCADE
  186.     ON UPDATE CASCADE,
  187.   CONSTRAINT `contact_ibfk_2`
  188.     FOREIGN KEY (`homePhoneID`)
  189.     REFERENCES `database_rugby`.`homePhone` (`homePhoneID`)
  190.     ON DELETE CASCADE
  191.     ON UPDATE CASCADE,
  192.   CONSTRAINT `contact_ibfk_3`
  193.     FOREIGN KEY (`mobilePhoneID`)
  194.     REFERENCES `database_rugby`.`mobilePhone` (`mobilePhoneID`)
  195.     ON DELETE CASCADE
  196.     ON UPDATE CASCADE,
  197.   CONSTRAINT `contact_ibfk_4`
  198.     FOREIGN KEY (`emailAddressID`)
  199.     REFERENCES `database_rugby`.`emailAddress` (`emailAddressID`)
  200.     ON DELETE CASCADE
  201.     ON UPDATE CASCADE)
  202. ENGINE = InnoDB;
  203.  
  204.  
  205. -- Create the "family" table.
  206. --
  207. -- This is a linking table
  208. -- that describes the many:many
  209. -- relationship between "parent"
  210. -- and "player" tables.
  211. DROP TABLE IF EXISTS `database_rugby`.`family` ;
  212. CREATE  TABLE IF NOT EXISTS `database_rugby`.`family` (
  213.   `parentID` INT(5) NOT NULL ,
  214.   `playerID` INT(5) NOT NULL ,
  215.   `parent_parentID` INT(5) NOT NULL ,
  216.   INDEX `playerID` (`playerID` ASC) ,
  217.   INDEX `fk_family_parent1` (`parent_parentID` ASC) ,
  218.   CONSTRAINT `family_ibfk_2`
  219.     FOREIGN KEY (`playerID` )
  220.     REFERENCES `database_rugby`.`player` (`playerID`)
  221.     ON DELETE CASCADE
  222.     ON UPDATE CASCADE,
  223.   CONSTRAINT `fk_family_parent1`
  224.     FOREIGN KEY (`parent_parentID`)
  225.     REFERENCES `database_rugby`.`parent` (`parentID`)
  226.     ON DELETE NO ACTION
  227.     ON UPDATE NO ACTION)
  228. ENGINE = InnoDB;
  229.  
  230.  
  231. -- Create the "qualificationSet" table.
  232. --
  233. -- This is a linking table
  234. -- that describes the many:many
  235. -- relationship between "coach"
  236. -- and "coachQualification" tables.
  237. DROP TABLE IF EXISTS `database_rugby`.`qualificationSet` ;
  238. CREATE  TABLE IF NOT EXISTS `database_rugby`.`qualificationSet` (
  239.   `coachID` INT(5) NOT NULL ,
  240.   `qualID` INT(5) NOT NULL ,
  241.   INDEX `coachID` (`coachID` ASC) ,
  242.   INDEX `qualID` (`qualID` ASC) ,
  243.   CONSTRAINT `qualificationSet_ibfk_1`
  244.     FOREIGN KEY (`coachID`)
  245.     REFERENCES `database_rugby`.`coach` (`coachID`)
  246.     ON DELETE CASCADE
  247.     ON UPDATE CASCADE,
  248.   CONSTRAINT `qualificationSet_ibfk_2`
  249.     FOREIGN KEY (`qualID`)
  250.     REFERENCES `database_rugby`.`coachQualification` (`qualID`)
  251.     ON DELETE CASCADE
  252.     ON UPDATE CASCADE)
  253. ENGINE = InnoDB;
  254.  
  255.  
  256. -- Create the "team" table.
  257. DROP TABLE IF EXISTS `database_rugby`.`team` ;
  258. CREATE  TABLE IF NOT EXISTS `database_rugby`.`team` (
  259.   `teamID` INT(5) NOT NULL AUTO_INCREMENT ,
  260.   `teamName` VARCHAR(50) NOT NULL ,
  261.   `teamYear` INT(2) NOT NULL ,
  262.   `gradeID` INT(5) NOT NULL ,
  263.   PRIMARY KEY (`teamID`) ,
  264.   INDEX `gradeID` (`gradeID` ASC) ,
  265.   CONSTRAINT `team_ibfk_1`
  266.     FOREIGN KEY (`gradeID`)
  267.     REFERENCES `database_rugby`.`grade` (`gradeID`)
  268.     ON DELETE CASCADE
  269.     ON UPDATE CASCADE)
  270. ENGINE = InnoDB;
  271.  
  272.  
  273. -- Create the "teamAllocation" table
  274. --
  275. -- this is a linking table for a
  276. -- many:many relationship between
  277. -- team and player tables.
  278. DROP TABLE IF EXISTS `database_rugby`.`teamAllocation` ;
  279.  
  280. CREATE  TABLE IF NOT EXISTS `database_rugby`.`teamAllocation` (
  281.   `teamID` INT(5) NOT NULL ,
  282.   `playerID` INT(5) NOT NULL ,
  283.   INDEX `teamID` (`teamID` ASC) ,
  284.   INDEX `playerID` (`playerID` ASC) ,
  285.   CONSTRAINT `teamallocation_ibfk_1`
  286.     FOREIGN KEY (`teamID` )
  287.     REFERENCES `database_rugby`.`team` (`teamID`)
  288.     ON DELETE CASCADE
  289.     ON UPDATE CASCADE,
  290.   CONSTRAINT `teamAllocation_ibfk_2`
  291.     FOREIGN KEY (`playerID`)
  292.     REFERENCES `database_rugby`.`player` (`playerID`)
  293.     ON DELETE CASCADE
  294.     ON UPDATE CASCADE)
  295. ENGINE = InnoDB;
  296.  
  297.  
  298. -- Create the "teamCoachAllocation" table.
  299. --
  300. -- This is a linking table
  301. -- that describes the many:many
  302. -- relationship between "coach"
  303. -- and "team" tables.
  304. DROP TABLE IF EXISTS `database_rugby`.`teamCoachAllocation` ;
  305. CREATE TABLE `database_rugby`.`teamCoachAllocation` (
  306.   `coachID` INT(5) NOT NULL ,
  307.   `teamID` INT(5) NOT NULL ,
  308.   INDEX `coachID` (`coachID` ASC) ,
  309.   INDEX `teamID` (`teamID` ASC) ,
  310.   CONSTRAINT `teamCoachAllocation_ibfk_1`
  311.     FOREIGN KEY (`coachID`)
  312.     REFERENCES `database_rugby`.`coach` (`coachID`)
  313.     ON DELETE CASCADE
  314.     ON UPDATE CASCADE,
  315.   CONSTRAINT `teamCoachAllocation_ibfk_2`
  316.     FOREIGN KEY (`teamID`)
  317.     REFERENCES `database_rugby`.`team` (`teamID`)
  318.     ON DELETE CASCADE
  319.     ON UPDATE CASCADE)
  320. ENGINE = InnoDB;
  321.        
  322. -- database_data.sql.
  323. -- This sql script inserts data into the
  324. -- rugby club database.
  325.  
  326. USE database_rugby;
  327.  
  328. TRUNCATE TABLE database_rugby.person;
  329.  
  330. -- Insert new persons which will be
  331. -- players.
  332. INSERT INTO database_rugby.person (
  333. firstName,
  334. lastName,
  335. dateOfBirth,
  336. streetAddress,
  337. suburbAddress,
  338. cityAddress)
  339. VALUES(
  340. "Michael",
  341. "Peck",
  342. '2002-12-10',
  343. "45 Skibo Street",
  344. "Caversham",
  345. "Dunedin");
  346.  
  347. INSERT INTO database_rugby.person (
  348. firstName,
  349. lastName,
  350. dateOfBirth,
  351. streetAddress,
  352. suburbAddress,
  353. cityAddress)
  354. VALUES(
  355. "Matt",
  356. "Petersen",
  357. '2001-06-15',
  358. "192 Bayview Road",
  359. "South Dunedin",
  360. "Dunedin");
  361.  
  362. INSERT INTO database_rugby.person (
  363. firstName,
  364. lastName,
  365. dateOfBirth,
  366. streetAddress,
  367. suburbAddress,
  368. cityAddress)
  369. VALUES(
  370. "Christopher",
  371. "Petersen",
  372. '2003-02-19',
  373. "192 Bayview Road",
  374. "South Dunedin",
  375. "Dunedin");
  376.  
  377. INSERT INTO database_rugby.person (
  378. firstName,
  379. lastName,
  380. dateOfBirth,
  381. streetAddress,
  382. suburbAddress,
  383. cityAddress)
  384. VALUES(
  385. "Richard",
  386. "Michaels",
  387. '2002-04-08',
  388. "15 Fitzroy Street",
  389. "Caversham",  
  390. "Dunedin");
  391.  
  392. INSERT INTO database_rugby.person (
  393. firstName,
  394. lastName,
  395. dateOfBirth,
  396. streetAddress,
  397. suburbAddress,
  398. cityAddress)
  399. VALUES(
  400. "Shaun",
  401. "Michaels",
  402. '2003-11-11',
  403. "15 Fitzroy Street",
  404. "Caversham",  
  405. "Dunedin");
  406.  
  407. INSERT INTO database_rugby.person (
  408. firstName,
  409. lastName,
  410. dateOfBirth,
  411. streetAddress,
  412. suburbAddress,
  413. cityAddress)
  414. VALUES(
  415. "Harry",
  416. "Dackers",
  417. '2004-02-11',
  418. "32 Peter Street",
  419. "Caversham",  
  420. "Dunedin");
  421.  
  422. INSERT INTO database_rugby.person (
  423. firstName,
  424. lastName,
  425. dateOfBirth,
  426. streetAddress,
  427. suburbAddress,
  428. cityAddress)
  429. VALUES(
  430. "Daniel",
  431. "Mitchell",
  432. '2002-05-19',
  433. "112 South Road",
  434. "Caversham",  
  435. "Dunedin");
  436.  
  437. -- Insert new persons which will be
  438. -- parents.
  439. INSERT INTO database_rugby.person (
  440. firstName,
  441. lastName,
  442. dateOfBirth,
  443. streetAddress,
  444. suburbAddress,
  445. cityAddress)
  446. VALUES(
  447. "Gregory",
  448. "Peck",
  449. '1971-07-22',
  450. "123 Burns Street",
  451. "South Dunedin",
  452. "Dunedin");
  453.  
  454.  
  455. INSERT INTO database_rugby.person (
  456. firstName,
  457. lastName,
  458. dateOfBirth,
  459. streetAddress,
  460. suburbAddress,
  461. cityAddress)
  462. VALUES(
  463. "Laura",
  464. "Peck",
  465. '1979-09-08',
  466. "123 Burns Street",
  467. "South Dunedin",
  468. "Dunedin");
  469.  
  470. INSERT INTO database_rugby.person (
  471. firstName,
  472. lastName,
  473. dateOfBirth,
  474. streetAddress,
  475. suburbAddress,
  476. cityAddress)
  477. VALUES(
  478. "Martha",
  479. "Petersen",
  480. '1973-12-07',
  481. "192 Bayview Road",
  482. "South Dunedin",
  483. "Dunedin");
  484.  
  485. INSERT INTO database_rugby.person (
  486. firstName,
  487. lastName,
  488. dateOfBirth,
  489. streetAddress,
  490. suburbAddress,
  491. cityAddress)
  492. VALUES(
  493. "Chris",
  494. "Michaels",
  495. '1967-08-07',
  496. "15 Fitzroy Street",
  497. "Caversham",  
  498. "Dunedin");
  499.  
  500. INSERT INTO database_rugby.person (
  501. firstName,
  502. lastName,
  503. dateOfBirth,
  504. streetAddress,
  505. suburbAddress,
  506. cityAddress)
  507. VALUES(
  508. "Nadine",
  509. "Michaels",
  510. '1973-10-19',
  511. "15 Fitzroy Street",
  512. "Caversham",  
  513. "Dunedin");
  514.  
  515. INSERT INTO database_rugby.person (
  516. firstName,
  517. lastName,
  518. dateOfBirth,
  519. streetAddress,
  520. suburbAddress,
  521. cityAddress)
  522. VALUES(
  523. "Barry",
  524. "Dackers",
  525. '1965-02-11',
  526. "32 Peter Street",
  527. "Caversham",  
  528. "Dunedin");
  529.  
  530. INSERT INTO database_rugby.person (
  531. firstName,
  532. lastName,
  533. dateOfBirth,
  534. streetAddress,
  535. suburbAddress,
  536. cityAddress)
  537. VALUES(
  538. "Kevin",
  539. "Mitchell",
  540. '1972-05-19',
  541. "112 South Road",
  542. "Caversham",  
  543. "Dunedin");
  544.  
  545. INSERT INTO database_rugby.person (
  546. firstName,
  547. lastName,
  548. dateOfBirth,
  549. streetAddress,
  550. suburbAddress,
  551. cityAddress)
  552. VALUES(
  553. "Rebecca",
  554. "Mitchell",
  555. '1978-01-23',
  556. "112 South Road",
  557. "Caversham",  
  558. "Dunedin");
  559.  
  560. -- Insert schools into school table.
  561. TRUNCATE TABLE database_rugby.school;
  562. INSERT INTO database_rugby.school(
  563. schoolName)
  564. VALUES(
  565. "College Street School");
  566.  
  567. INSERT INTO database_rugby.school(
  568. schoolName)
  569. VALUES(
  570. "Macandrew Intermediate School");
  571.  
  572. INSERT INTO database_rugby.school(
  573. schoolName)
  574. VALUES(
  575. "Carlton Hill Primary");
  576.  
  577. INSERT INTO database_rugby.school(
  578. schoolName)
  579. VALUES(
  580. "Caversham Primary School");
  581.  
  582. INSERT INTO database_rugby.school(
  583. schoolName)
  584. VALUES(
  585. "Concord School");
  586.  
  587. -- Insert players into player table.
  588. TRUNCATE TABLE database_rugby.player;
  589. INSERT INTO database_rugby.player(
  590. personID,
  591. schoolID)
  592. VALUES(
  593.     (SELECT personID FROM database_rugby.person
  594.     WHERE database_rugby.person(firstName) = "Michael"
  595.     AND database_rugby.person(lastName) = "Peck"),
  596.     (SELECT schoolID FROM database_rugby.school
  597.     WHERE database_rugby.school(schoolName) =  "College Street School"));
  598.  
  599. INSERT INTO database_rugby.player(
  600. personID,
  601. schoolID)
  602. VALUES(
  603.     (SELECT personID FROM database_rugby.person
  604.     WHERE database_rugby.person(firstName) = "Matt"
  605.     AND database_rugby.person(lastName) = "Petersen"),
  606.     (SELECT schoolID FROM database_rugby.school
  607.     WHERE database_rugby.school(schoolName) =  "Macandrew Intermediate School"));
  608.  
  609. INSERT INTO database_rugby.player(
  610. personID,
  611. schoolID)
  612. VALUES(
  613.     (SELECT personID FROM database_rugby.person
  614.     WHERE database_rugby.person(firstName) = "Christopher"
  615.     AND database_rugby.person(lastName) = "Petersen"),
  616.     (SELECT schoolID FROM database_rugby.school
  617.     WHERE database_rugby.school(schoolName) =  "College Street School"));
  618.  
  619. INSERT INTO database_rugby.player(
  620. personID,
  621. schoolID)
  622. VALUES(
  623.     (SELECT personID FROM database_rugby.person
  624.     WHERE database_rugby.person(firstName) = "Richard"
  625.     AND database_rugby.person(lastName) = "Michaels"),
  626.     (SELECT schoolID FROM database_rugby.school
  627.     WHERE database_rugby.school(schoolName) =  "College Street School"));
  628.  
  629. INSERT INTO database_rugby.player(
  630. personID,
  631. schoolID)
  632. VALUES(
  633.     (SELECT personID FROM database_rugby.person
  634.     WHERE database_rugby.person(firstName) = "Shaun"
  635.     AND database_rugby.person(lastName) = "Michaels"),
  636.     (SELECT schoolID FROM database_rugby.school
  637.     WHERE database_rugby.school(schoolName) =  "College Street School"));
  638.  
  639. INSERT INTO database_rugby.player(
  640. personID,
  641. schoolID)
  642. VALUES(
  643.     (SELECT personID FROM database_rugby.person
  644.     WHERE database_rugby.person(firstName) = "Harry"
  645.     AND database_rugby.person(lastName) = "Dackers"),
  646.     (SELECT schoolID FROM database_rugby.school
  647.     WHERE database_rugby.school(schoolName) =  "Caversham Primary School"));
  648.  
  649. INSERT INTO database_rugby.player(
  650. personID,
  651. schoolID)
  652. VALUES(
  653.     (SELECT personID FROM database_rugby.person
  654.     WHERE database_rugby.person(firstName) = "Daniel"
  655.     AND database_rugby.person(lastName) = "Mitchell"),
  656.     (SELECT schoolID FROM database_rugby.school
  657.     WHERE database_rugby.school(schoolName) =  "Caversham Primary School"));
  658.        
  659. Welcome to the MySQL monitor.  Commands end with ; or g.
  660. Your MySQL connection id is 82
  661. Server version: 5.5.23 MySQL Community Server (GPL)
  662.  
  663. Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
  664.  
  665. Oracle is a registered trademark of Oracle Corporation and/or its
  666. affiliates. Other names may be trademarks of their respective
  667. owners.
  668.  
  669. Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
  670.  
  671. mysql> source c:scriptsdatabase_schema.sql
  672. Query OK, 16 rows affected (0.35 sec)
  673.  
  674. Query OK, 1 row affected (0.03 sec)
  675.  
  676. Database changed
  677. Query OK, 0 rows affected, 1 warning (0.00 sec)
  678.  
  679. Query OK, 0 rows affected (0.06 sec)
  680.  
  681. Query OK, 0 rows affected, 1 warning (0.00 sec)
  682.  
  683. Query OK, 0 rows affected (0.06 sec)
  684.  
  685. Query OK, 0 rows affected, 1 warning (0.00 sec)
  686.  
  687. Query OK, 0 rows affected (0.04 sec)
  688.  
  689. Query OK, 0 rows affected, 1 warning (0.00 sec)
  690.  
  691. Query OK, 0 rows affected (0.07 sec)
  692.  
  693. Query OK, 0 rows affected, 1 warning (0.00 sec)
  694.  
  695. Query OK, 0 rows affected (0.06 sec)
  696.  
  697. Query OK, 0 rows affected, 1 warning (0.00 sec)
  698.  
  699. Query OK, 0 rows affected (0.06 sec)
  700.  
  701. Query OK, 0 rows affected, 1 warning (0.01 sec)
  702.  
  703. Query OK, 0 rows affected (0.09 sec)
  704.  
  705. Query OK, 0 rows affected, 1 warning (0.00 sec)
  706.  
  707. Query OK, 0 rows affected (0.06 sec)
  708.  
  709. Query OK, 0 rows affected, 1 warning (0.01 sec)
  710.  
  711. Query OK, 0 rows affected (0.07 sec)
  712.  
  713. Query OK, 0 rows affected, 1 warning (0.00 sec)
  714.  
  715. Query OK, 0 rows affected (0.07 sec)
  716.  
  717. Query OK, 0 rows affected, 1 warning (0.00 sec)
  718.  
  719. Query OK, 0 rows affected (0.10 sec)
  720.  
  721. Query OK, 0 rows affected, 1 warning (0.00 sec)
  722.  
  723. Query OK, 0 rows affected (0.06 sec)
  724.  
  725. Query OK, 0 rows affected, 1 warning (0.00 sec)
  726.  
  727. Query OK, 0 rows affected (0.08 sec)
  728.  
  729. Query OK, 0 rows affected, 1 warning (0.00 sec)
  730.  
  731. Query OK, 0 rows affected (0.06 sec)
  732.  
  733. Query OK, 0 rows affected, 1 warning (0.00 sec)
  734.  
  735. Query OK, 0 rows affected (0.10 sec)
  736.  
  737. Query OK, 0 rows affected, 1 warning (0.01 sec)
  738.  
  739. Query OK, 0 rows affected (0.07 sec)
  740.  
  741. mysql> source c:scriptsdatabase_data.sql
  742. Database changed
  743. ERROR 1701 (42000): Cannot truncate a table referenced in a foreign key constrai
  744. nt (`database_rugby`.`contact`, CONSTRAINT `contact_ibfk_1` FOREIGN KEY (`person
  745. ID`) REFERENCES `database_rugby`.`person` (`personID`))
  746. ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint f
  747. ails (`database_rugby`.`person`, CONSTRAINT `fk_person_coach1` FOREIGN KEY (`coa
  748. ch_coachID2`) REFERENCES `coach` (`coachID`) ON DELETE NO ACTION ON UPDATE NO AC
  749. TION)
  750. ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint f
  751. ails (`database_rugby`.`person`, CONSTRAINT `fk_person_coach1` FOREIGN KEY (`coa
  752. ch_coachID2`) REFERENCES `coach` (`coachID`) ON DELETE NO ACTION ON UPDATE NO AC
  753. TION)
  754. ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint f
  755. ails (`database_rugby`.`person`, CONSTRAINT `fk_person_coach1` FOREIGN KEY (`coa
  756. ch_coachID2`) REFERENCES `coach` (`coachID`) ON DELETE NO ACTION ON UPDATE NO AC
  757. TION)
  758. ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint f
  759. ails (`database_rugby`.`person`, CONSTRAINT `fk_person_coach1` FOREIGN KEY (`coa
  760. ch_coachID2`) REFERENCES `coach` (`coachID`) ON DELETE NO ACTION ON UPDATE NO AC
  761. TION)
  762. ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint f
  763. ails (`database_rugby`.`person`, CONSTRAINT `fk_person_coach1` FOREIGN KEY (`coa
  764. ch_coachID2`) REFERENCES `coach` (`coachID`) ON DELETE NO ACTION ON UPDATE NO AC
  765. TION)
  766. ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint f
  767. ails (`database_rugby`.`person`, CONSTRAINT `fk_person_coach1` FOREIGN KEY (`coa
  768. ch_coachID2`) REFERENCES `coach` (`coachID`) ON DELETE NO ACTION ON UPDATE NO AC
  769. TION)
  770. ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint f
  771. ails (`database_rugby`.`person`, CONSTRAINT `fk_person_coach1` FOREIGN KEY (`coa
  772. ch_coachID2`) REFERENCES `coach` (`coachID`) ON DELETE NO ACTION ON UPDATE NO AC
  773. TION)
  774. ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint f
  775. ails (`database_rugby`.`person`, CONSTRAINT `fk_person_coach1` FOREIGN KEY (`coa
  776. ch_coachID2`) REFERENCES `coach` (`coachID`) ON DELETE NO ACTION ON UPDATE NO AC
  777. TION)
  778. ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint f
  779. ails (`database_rugby`.`person`, CONSTRAINT `fk_person_coach1` FOREIGN KEY (`coa
  780. ch_coachID2`) REFERENCES `coach` (`coachID`) ON DELETE NO ACTION ON UPDATE NO AC
  781. TION)
  782. ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint f
  783. ails (`database_rugby`.`person`, CONSTRAINT `fk_person_coach1` FOREIGN KEY (`coa
  784. ch_coachID2`) REFERENCES `coach` (`coachID`) ON DELETE NO ACTION ON UPDATE NO AC
  785. TION)
  786. ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint f
  787. ails (`database_rugby`.`person`, CONSTRAINT `fk_person_coach1` FOREIGN KEY (`coa
  788. ch_coachID2`) REFERENCES `coach` (`coachID`) ON DELETE NO ACTION ON UPDATE NO AC
  789. TION)
  790. ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint f
  791. ails (`database_rugby`.`person`, CONSTRAINT `fk_person_coach1` FOREIGN KEY (`coa
  792. ch_coachID2`) REFERENCES `coach` (`coachID`) ON DELETE NO ACTION ON UPDATE NO AC
  793. TION)
  794. ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint f
  795. ails (`database_rugby`.`person`, CONSTRAINT `fk_person_coach1` FOREIGN KEY (`coa
  796. ch_coachID2`) REFERENCES `coach` (`coachID`) ON DELETE NO ACTION ON UPDATE NO AC
  797. TION)
  798. ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint f
  799. ails (`database_rugby`.`person`, CONSTRAINT `fk_person_coach1` FOREIGN KEY (`coa
  800. ch_coachID2`) REFERENCES `coach` (`coachID`) ON DELETE NO ACTION ON UPDATE NO AC
  801. TION)
  802. ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint f
  803. ails (`database_rugby`.`person`, CONSTRAINT `fk_person_coach1` FOREIGN KEY (`coa
  804. ch_coachID2`) REFERENCES `coach` (`coachID`) ON DELETE NO ACTION ON UPDATE NO AC
  805. TION)
  806. ERROR 1701 (42000): Cannot truncate a table referenced in a foreign key constrai
  807. nt (`database_rugby`.`player`, CONSTRAINT `player_ibfk_1` FOREIGN KEY (`schoolID
  808. `) REFERENCES `database_rugby`.`school` (`schoolID`))
  809. Query OK, 1 row affected (0.01 sec)
  810.  
  811. Query OK, 1 row affected (0.01 sec)
  812.  
  813. Query OK, 1 row affected (0.01 sec)
  814.  
  815. Query OK, 1 row affected (0.00 sec)
  816.  
  817. Query OK, 1 row affected (0.00 sec)
  818.  
  819. ERROR 1701 (42000): Cannot truncate a table referenced in a foreign key constrai
  820. nt (`database_rugby`.`person`, CONSTRAINT `fk_person_player1` FOREIGN KEY (`play
  821. er_playerID2`) REFERENCES `database_rugby`.`player` (`playerID`))
  822. ERROR 1305 (42000): FUNCTION database_rugby.person does not exist
  823. ERROR 1305 (42000): FUNCTION database_rugby.person does not exist
  824. ERROR 1305 (42000): FUNCTION database_rugby.person does not exist
  825. ERROR 1305 (42000): FUNCTION database_rugby.person does not exist
  826. ERROR 1305 (42000): FUNCTION database_rugby.person does not exist
  827. ERROR 1305 (42000): FUNCTION database_rugby.person does not exist
  828. ERROR 1305 (42000): FUNCTION database_rugby.person does not exist
  829. mysql>
  830.        
  831. SET foreign_key_checks = 0;
  832.        
  833. SET foreign_key_checks = 1;
  834.        
  835. -- Create the "person" table.
  836. --
  837. -- This table has one:one relationships
  838. -- with the parent, coach and player
  839. -- tables.
  840. DROP TABLE IF EXISTS `person` ;                --- no change
  841. CREATE TABLE `person` (
  842.   `personID` INT(5) NOT NULL AUTO_INCREMENT ,
  843.   --- ...
  844.   --- several columns omitted for clarity
  845.   --- ...
  846.   PRIMARY KEY (`personID`))
  847. ENGINE = InnoDB;
  848.        
  849. -- Create the "parent" table.
  850. DROP TABLE IF EXISTS `parent` ;
  851. CREATE TABLE `parent` (
  852.   --- `parentID` INT(5) NOT NULL ,             --- removed
  853.  
  854.   `personID` INT(5) NOT NULL ,
  855.  
  856.   --- PRIMARY KEY (`parentID`, `personID`),    --- removed
  857.  
  858.   PRIMARY KEY (`personID`),                    --- this part only as PK
  859.                                                --- which is also a FK
  860.   FOREIGN KEY (`personID`)                     --- as previously (no change here)
  861.     REFERENCES `person` (`personID`)
  862.     ON DELETE CASCADE
  863.     ON UPDATE CASCADE)
  864. ENGINE = InnoDB;
  865.        
  866. -- Create the "school" table.
  867. -- omitted for clarity
  868. --
  869. --    
  870. -- Create the "player" table.
  871. --
  872. -- Inherits fields from the "person"
  873. -- and "school" tables.
  874. DROP TABLE IF EXISTS `player` ;
  875. CREATE TABLE `player` (
  876.   --- `playerID` INT(5) NOT NULL ,             --- removed
  877.   `personID` INT(5) NOT NULL ,
  878.   `schoolID` INT(5) NOT NULL ,
  879.   PRIMARY KEY (`personID`),                    --- Primary Key
  880.   FOREIGN KEY (`personID`)                     --- that is also Foreign Key
  881.     REFERENCES `person` (`personID`)
  882.     ON DELETE CASCADE
  883.     ON UPDATE CASCADE,
  884.   FOREIGN KEY (`schoolID`)
  885.     REFERENCES `school` (`schoolID`)
  886.     ON DELETE CASCADE
  887.     ON UPDATE CASCADE)
  888. ENGINE = InnoDB;