Programming Exercise I Construction (Cont.)

  1. MySQL DB Implementation Using MySQL Text Monitor (SQL)
  2. The list below shows how to use MySQL text monitor to create a database. The SQL commands can be found from here.

    Note that MySQL text monitor is not working yet. Use MySQL Workbench instead.

    An Example of MySQL Database Processing
     undcemcs02> mysql -h undcsmysql.mysql.database.azure.com -u userid -p 
      Enter password: ********** 
    
      Welcome to the MySQL monitor.  Commands end with ; or \g.
      Your MySQL connection id is 2140
      Server version: 5.1.73 Source distribution
      Copyright (c) 2000, 2012, Oracle and/or its affiliates.
      All rights reserved. Oracle is a registered trademark of
      Oracle Corporation and/or its
      affiliates. Other names may be trademarks of their
      respective owners.
    
      Type 'help;' or '\h' for help. Type '\c' to clear the
      current input statement.
    
     mysql> show databases; 
     +--------------------+
     | Database           |
     +--------------------+
     | information_schema |
     | wenchen            |
     +--------------------+
     2 rows in set (0.00 sec)
    
     mysql> -- Comment: wenchen is the instructor’s database 
     mysql> use wenchen; 
     Database changed
    
     mysql> DROP TABLE IF EXISTS take1;
     Query OK, 0 row affected (0.234 sec)
    
     mysql> DROP TABLE IF EXISTS course1;
     Query OK, 0 row affected (0.328 sec)
    
     mysql> DROP TABLE IF EXISTS student1;
     Query OK, 0 row affected (0.219 sec)
    
     mysql> create table student1 ( 
         ->   sid    INT AUTO_INCREMENT PRIMARY KEY, 
         ->   name   VARCHAR(64) NOT NULL, 
         ->   email  VARCHAR(32) NOT NULL ); 
     Query OK, 0 rows affected (0.219 sec)
    
     mysql> INSERT INTO student1 ( name, email ) VALUES ( 
         ->   'Super Mario', 'super.mario@und.edu' ); 
     Query OK, 1 row affected (0.141 sec)
    
     mysql> INSERT INTO student1 ( name, email ) VALUES ( 
         ->   'Digi Mon', 'digi.mon@ndus.edu' ); 
     Query OK, 1 row affected (0.079 sec)
    
     mysql> INSERT INTO student1 ( name, email ) VALUES ( 
         ->   'Poke Mon', 'poke.mon@und.edu' ); 
     Query OK, 1 row affected (0.078 sec)
    
     mysql> INSERT INTO student1 ( name, email ) VALUES ( 
         ->   'Sponge Bob', 'sponge@gmail.com' ); 
     Query OK, 1 row affected (0.078 sec)
    
     mysql> SELECT * FROM student1; 
     +-----+-------------+---------------------+
     | sid | name        | email               |
     +-----+-------------+---------------------+
     | 1   | Super Mario | super.mario@und.edu |
     | 2   | Digi Mon    | digi.mon@ndus.edu   |
     | 3   | Poke Mon    | poke.mon@und.edu    |
     | 4   | Sponge Bob  | sponge@gmail.com    |
     +-----+-------------+---------------------+
     4 rows in set (0.031 sec)
    
     mysql> create table course1 ( 
         ->   cid     CHAR(12) PRIMARY KEY, 
         ->   title   VARCHAR(64) NOT NULL, 
         ->   room    VARCHAR(16) NOT NULL, 
         ->   credit  INT NOT NULL ); 
     Query OK, 0 rows affected (0.218 sec)
    
     mysql> INSERT INTO course1 VALUES ( 
         ->   'CSCI260', '.NET and World Wide Web Programming', 'CEC 205', 3 ); 
     Query OK, 1 row affected (0.141 sec)
    
     mysql> INSERT INTO course1 VALUES ( 
         ->   'DATA520', 'Databases', 'Upson II 265', 3 ); 
     Query OK, 1 row affected (0.078 sec)
    
     mysql> INSERT INTO course1 VALUES ( 
         ->   'DATA525', 'Data Engineering and Mining', 'Harrington 218', 3 ); 
     Query OK, 1 row affected (0.078 sec)
    
     mysql> INSERT INTO course1 VALUES ( 
         ->   'CSCI513', 'Advanced Databases', 'Harrington 364', 3 ); 
     Query OK, 1 row affected (0.094 sec)
    
     mysql> SELECT * FROM course1; 
     +---------+-------------------------------------+----------------+--------+
     | cid     | title                               | room           | credit |
     +---------+-------------------------------------+----------------+--------+
     | CSCI260 | .NET and World Wide Web Programming | CEC 205        | 3      |
     | DATA520 | Databases                           | Upson II 265   | 3      |
     | DATA525 | Data Engineering and Mining         | Harrington 218 | 3      |
     | CSCI513 | Advanced Databases                  | Harrington 364 | 3      |
     +---------+-------------------------------------+----------------+--------+
     4 rows in set (0.031 sec)
    
     mysql> create table take1 ( 
         ->   sid       INT NOT NULL, 
         ->   cid       CHAR(12) NOT NULL, 
         ->   semester  VARCHAR(12) NOT NULL, 
         ->   PRIMARY KEY ( sid, cid ), 
         ->   FOREIGN KEY ( sid ) REFERENCES student1( sid ) ON DELETE CASCADE, 
         ->   FOREIGN KEY ( cid ) REFERENCES course1( cid ) ON DELETE CASCADE ) 
         ->     ENGINE=InnoDB; 
     Query OK, 0 rows affected (0.265 sec)
    
     mysql> INSERT INTO take1 SELECT sid, 'DATA520', 'Fall 2022' 
         ->   FROM student1 WHERE name ='Poke Mon'; 
     Query OK, 1 row affected (0.125 sec)
    
     mysql> INSERT INTO take1 SELECT sid, 'DATA525', 'Fall 2022' 
         ->   FROM student1 WHERE name='Poke Mon'; 
     Query OK, 1 row affected (0.078 sec)
    
     mysql> INSERT INTO take1 SELECT sid, 'CSCI260', 'Fall 2022' 
         ->   FROM student1 WHERE name='Digi Mon'; 
     Query OK, 1 row affected (0.078 sec)
    
     mysql> INSERT INTO take1 SELECT sid, 'CSCI513', 'Spring 2023' 
         ->   FROM student1 WHERE name='Sponge Bob'; 
     Query OK, 1 row affected (0.063 sec)
    
     mysql> SELECT s.name, c.title FROM student1 s, course1 c, take1 t 
         ->   WHERE UPPER(s.name) LIKE '%MON%' AND s.sid=t.sid AND t.cid=c.cid; 
    
     +----------+-------------------------------------+
     | name     | title                               |
     +----------+-------------------------------------+
     | Digi Mon | .NET and World Wide Web Programming |
     | Poke Mon | Databases                           |
     | Poke Mon | Data Engineering and Mining         |
     +----------+-------------------------------------+
     3 rows in set (0.031 sec)
    
     mysql> commit; 
     Query OK, 0 rows affected (0.00 sec)
    
     mysql> exit; 
     Bye
    
     undcemcs02>

    Note that this database implementation is only an example and is not related to this exercise.
    The italic, white text on navy background is entered by users.
    The wenchen is the instructor’s database. The MySQL DBA should assign a different database to you.